aspire init
Initialize Aspire in an existing codebase by creating an AppHost project, a ServiceDefaults project, and optionally adding references to existing projects.Usage
Description
Theaspire init command adds Aspire orchestration to an existing .NET solution. It detects your solution file, creates the necessary Aspire projects, and guides you through integrating existing projects into your AppHost.
What it Does
- Detects your solution - Walks up the directory tree to find a
.slnfile - Creates AppHost project - Adds a new
<SolutionName>.AppHostproject for orchestration - Creates ServiceDefaults project - Adds a new
<SolutionName>.ServiceDefaultsproject for shared configuration - Adds projects to solution - Both new projects are added to your solution
- Integrates existing projects - Prompts you to add references to existing executable projects
- Adds ServiceDefaults references - Optionally adds ServiceDefaults to selected projects
Behavior Without a Solution
If no solution file is found,aspire init creates a single-file AppHost in the current directory using the aspire-apphost-singlefile template.
Options
The NuGet source to use for project templatesExample:
--source https://api.nuget.org/v3/index.jsonThe version of the project templates to useExample:
--version 10.0.0-preview.1.25067.1Channel to use for templates:
stable, daily, or staging (when enabled)If not specified, uses the configured channel from aspire config get channel or defaults to stable.The programming language for the AppHost:
csharp or typescriptFor TypeScript AppHosts, a polyglot AppHost is created without solution integration.Examples
Initialize in an existing solution
Create a single-file AppHost
Use a specific template version
Use the daily channel
Create a TypeScript AppHost
Interactive Prompts
Project Selection
When initializing an existing solution, you’ll be prompted to select which executable projects to add to your AppHost:OutputType of Exe or WinExe and supported target frameworks (net8.0, net9.0, net10.0) are shown.
ServiceDefaults Selection
After selecting projects to add, you’ll be prompted to choose which projects should reference ServiceDefaults:Template Version Selection
If multiple template versions are available, you’ll be prompted to choose:Files Created
For a solution namedMySolution, the following structure is created:
Target Framework Selection
The AppHost project’s target framework is automatically set to the highest framework version of all selected projects:- If you select projects targeting
net9.0andnet10.0, the AppHost will targetnet10.0 - If no projects are selected, the AppHost defaults to
net9.0
Configuration
The--channel option can be set globally to avoid specifying it each time:
See Also
- aspire new - Create a new Aspire application from a template
- aspire run - Run your initialized AppHost
- aspire add - Add integrations to your AppHost