Aller au contenu
DocsTry Aspire
DocsTry

Get started with the PowerShell integration

Ce contenu n’est pas encore disponible dans votre langue.

PowerShell logo ⭐ Community Toolkit

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.

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
  • 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.
  1. Add CommunityToolkit.Aspire.Hosting.PowerShell to your AppHost. You can use aspire add communitytoolkit-powershell or install the NuGet package directly.

  2. 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();
  3. Configure arguments, dependencies, connection-string variables, and lifecycle behavior in the PowerShell AppHost reference.

    Configure PowerShell resources