Get started with the PowerShell integration
Esta página aún no está disponible en tu idioma.
The Community Toolkit PowerShell hosting integration runs PowerShell scripts in an in-process runspace pool that Aspire manages. Model setup, provisioning, and administrative scripts alongside your application resources, view their logs and states in the dashboard, and make later scripts wait for earlier ones to finish.
How the pieces fit together
Section titled “How the pieces fit together”The integration is a hosting integration installed in your AppHost. A PowerShell runspace pool resource hosts one or more script resources. Aspire starts the pool, starts each script after its dependencies are ready, and reports the pool and script lifecycle in the dashboard.
architecture-beta group apphost(server)[AppHost] group scripts(server)[PowerShell resources] service hosting(server)[PowerShell hosting integration] in apphost service pool(server)[Runspace pool] in scripts service script(server)[Script resource] in scripts hosting:R --> L:pool pool:R --> L:script
Prerequisites
Section titled “Prerequisites”- Create an Aspire AppHost in C# or TypeScript.
- Optionally install PowerShell to develop and test scripts outside the AppHost. The integration runs scripts in-process through the PowerShell SDK, so it doesn’t invoke
pwsh.
-
Install the hosting package
Section titled “Install the hosting package”Add
CommunityToolkit.Aspire.Hosting.PowerShellto your AppHost. You can useaspire add communitytoolkit-powershellor install the NuGet package directly. -
Add a pool and a script
Section titled “Add a pool and a script”Add a named PowerShell pool, then add a script to it. The following script appears as a resource in the dashboard.
AppHost.cs var builder = DistributedApplication.CreateBuilder(args);var scripts = builder.AddPowerShell("scripts");scripts.AddScript("setup", """Write-Information "Preparing the application"""");builder.Build().Run();apphost.mts import { createBuilder } from './.aspire/modules/aspire.mjs';const builder = await createBuilder();const scripts = await builder.addPowerShell('scripts');await scripts.addScript('setup','Write-Information "Preparing the application"');await builder.build().run(); -
Configure scripts in the AppHost
Section titled “Configure scripts in the AppHost”Configure arguments, dependencies, connection-string variables, and lifecycle behavior in the PowerShell AppHost reference.
Configure PowerShell resources