title | description | ms.date |
---|---|---|
.NET Aspire tooling |
Learn about essential tooling concepts for .NET Aspire. |
03/11/2024 |
.NET Aspire includes tooling to help you create and configure cloud-native apps. The tooling includes useful starter project templates and other features to streamline getting started with .NET Aspire for both Visual Studio and CLI workflows. In the sections ahead, you'll learn how to work with .NET Aspire tooling and explore the following tasks:
[!div class="checklist"]
- Install .NET Aspire and its dependencies
- Create starter project templates using Visual Studio or the .NET CLI
- Install .NET Aspire components
- Work with the .NET Aspire dashboard
To work with .NET Aspire, you'll need the following installed locally:
- .NET 8.0
- .NET Aspire workload
- Docker Desktop
- Integrated Developer Environment (IDE) or code editor, such as:
- Visual Studio 2022 Preview version 17.10 or higher (Optional)
- Visual Studio Code (Optional)
The .NET Aspire workload installs internal dependencies and makes available other tooling, such as project templates and Visual Studio features. There are two ways to install the .NET Aspire workload. If you prefer to use Visual Studio Code, follow the .NET CLI instructions:
Visual Studio 2022 17.10 Preview 1 or higher includes the .NET Aspire preview 4 workload by default. To verify that you have the .NET Aspire workload installed, run the following command:
dotnet workload list
If you have an earlier version of Visual Studio 2022 Preview, you can either upgrade to Visual Studio 2022 17.10 Preview 1 or you can install the .NET Aspire workload using the following steps:
To install the .NET Aspire workload in Visual Studio 2022 Preview, use the Visual Studio installer.
-
Open the Visual Studio Installer.
-
Select Modify next to Visual Studio 2022 Preview.
-
Select the ASP.NET and web development workload.
-
On the Installation details panel, select .NET Aspire SDK (Preview).
-
Select Modify to install the .NET Aspire component.
:::image type="content" source="../media/install-aspire-workload-visual-studio.png" lightbox="../media/install-aspire-workload-visual-studio.png" alt-text="A screenshot showing how to install the .NET Aspire workload with the Visual Studio installer.":::
-
To ensure that you install the latest version of the .NET Aspire workload, run the following dotnet workload update command before you install .NET Aspire:
dotnet workload update
-
To install the .NET Aspire workload from the .NET CLI, use the dotnet workload install command:
dotnet workload install aspire
-
To check your version of .NET Aspire, run this command:
dotnet workload list
To ensure that you install the latest version of the .NET Aspire workload, run the following dotnet workload update command before you install .NET Aspire:
dotnet workload update
To install the .NET Aspire workload from the .NET CLI, use the dotnet workload install command:
dotnet workload install aspire
To check your version of .NET Aspire, run this command:
dotnet workload list
Note
The .NET 9.0 SDK causes issues with the .NET Aspire workloads ability to display templates, and create projects from the templates. If you're using .NET 9.0, know that your ability to create new .NET Aspire apps is currently limited. For more information, see .NET Aspire preview-3 cannot create app when .NET 9 is installed and .NET Aspire preview-3 installed with Visual Studio 17.10 doesn't show templates.
The .NET Aspire workload makes available .NET Aspire project templates. These project templates allow you to create new apps pre-configured with the .NET Aspire project structure and default settings. These projects also provide a unified debugging experience across the different resources of your app.
There are currently four project templates available:
-
.NET Aspire Application: A minimal .NET Aspire app that includes the following:
-
AspireSample.AppHost: An orchestrator project designed to connect and configure the different projects and services of your app.
-
AspireSample.ServiceDefaults: A .NET Aspire shared project to manage configurations that are reused across the projects in your solution related to resilience, service discovery, and telemetry.
-
-
.NET Aspire Starter Application: In addition to the .AppHost and .ServiceDefaults projects, the .NET Aspire Starter Application also includes the following:
-
AspireSample.ApiService: An ASP.NET Core Minimal API project is used to provide data to the frontend. This project depends on the shared AspireSample.ServiceDefaults project.
-
AspireSample.Web: An ASP.NET Core Blazor App project with default .NET Aspire service configurations, this project depends on the AspireSample.ServiceDefaults project.
-
-
.NET Aspire App Host: A standalone .AppHost project that can be used to orchestrate and manage the different projects and services of your app.
-
.NET Aspire Service Defaults: A standalone .ServiceDefaults project that can be used to manage configurations that are reused across the projects in your solution related to resilience, service discovery, and telemetry.
Use Visual Studio or the .NET CLI to create new apps using these project templates. Explore additional .NET Aspire project templates in the .NET Aspire samples repository.
To create a .NET Aspire project using Visual Studio, search for Aspire in the Visual Studio new project window and select your desired template.
:::image type="content" source="../media/aspire-templates.png" lightbox="../media/aspire-templates.png" alt-text="The .NET Aspire project templates in Visual Studio.":::
To see which .NET Aspire project templates are available, use the dotnet new list command, passing in the search term aspire
:
dotnet new list aspire
When the .NET Aspire workload is installed, you'll see the following .NET Aspire templates:
These templates matched your input: 'aspire'
Template Name Short Name Language Tags
------------------------------- ---------------------- -------- -------------------------------------------------------
.NET Aspire App Host aspire-apphost [C#] Common/.NET Aspire/Cloud
.NET Aspire Application aspire [C#] Common/.NET Aspire/Cloud/Web/Web API/API/Service
.NET Aspire Service Defaults aspire-servicedefaults [C#] Common/.NET Aspire/Cloud/Web/Web API/API/Service
.NET Aspire Starter Application aspire-starter [C#] Common/.NET Aspire/Blazor/Web/Web API/API/Service/Cloud
To create a .NET Aspire project using the .NET CLI, use the dotnet new
command and specify which template you would like to create.
To create a basic .NET Aspire project:
dotnet new aspire
To create a .NET Aspire project with a sample UI and API included:
dotnet new aspire-starter
.NET Aspire templates that expose the app host project also include a useful dashboard that can be used to monitor and inspect various aspects of your app, such as logs, traces, and environment configurations. This dashboard is designed to improve the local development experience and provides an overview of the overall state and structure of your app.
The .NET Aspire dashboard is only visible while the app is running and starts automatically when you start the .AppHost project. Visual Studio launches both your app and the .NET Aspire dashboard for you automatically in your browser. If you start the app using the .NET CLI, copy and paste the dashboard URL from the output into your browser, or hold Ctrl and select the link (if your terminal supports hyperlinks).
:::image type="content" source="../media/run-dashboard-cli.png" alt-text="A screenshot showing how to launch the dashboard using the CLI.":::
The left navigation provides links to the different parts of the dashboard, each of which you'll explore in the following sections.
:::image type="content" source="media/dashboard/projects.png" lightbox="media/dashboard/projects.png" alt-text="A screenshot of the .NET Aspire dashboard Projects page.":::
Visual Studio provides additional features for working with .NET Aspire components and the App Host orchestrator project. These features are currently not available in Visual Studio Code or through the CLI.
You add .NET Aspire components to your app like any other NuGet package using Visual Studio. However, Visual Studio also provides UI options to add .NET Aspire components directly.
-
In Visual Studio, right click on the project you want to add an .NET Aspire component to and select Add > .NET Aspire Component....
:::image type="content" source="../media/visual-studio-add-aspire-component.png" lightbox="../media/visual-studio-add-aspire-component.png" alt-text="The Visual Studio context menu displaying the Add .NET Aspire Component option.":::
-
The package manager will open with search results pre-configured (populating filter criteria) for .NET Aspire components, allowing you to easily browse and select the desired component. The Include prerelease checkbox needs to be checked to see preview components.
:::image type="content" source="../media/visual-studio-add-aspire-comp-nuget.png" lightbox="../media/visual-studio-add-aspire-comp-nuget.png" alt-text="The Visual Studio context menu displaying the Add .NET Aspire options.":::
For more information on .NET Aspire components, see .NET Aspire components overview.
You can add .NET Aspire orchestration projects to an existing app using the following steps:
-
In Visual Studio, right click on an existing project and select Add > .NET Aspire Orchestrator Support...
:::image type="content" source="../media/visual-studio-add-aspire-orchestrator.png" lightbox="../media/visual-studio-add-aspire-orchestrator.png" alt-text="The Visual Studio context menu displaying the Add .NET Aspire Orchestrator Support option.":::
-
A dialog window will open with a summary of the .AppHost and .ServiceDefaults projects that will be added to your solution.
:::image type="content" source="../media/add-orchestrator-app.png" alt-text="A screenshot showing the Visual Studio add .NET Aspire orchestration summary.":::
-
Select OK and the following changes will be applied:
- The .AppHost and .ServiceDefault orchestration projects will be added to your solution.
- A call to
builder.AddServiceDefaults
will be added to the Program.cs file of your original project. - A reference to your original project will be added to the Program.cs file of the .AppHost project.
For more information on .NET Aspire orchestration, see .NET Aspire orchestration overview.
Visual Studio provides the option to Enlist in Aspire orchestration during the new project workflow. Select this option to have Visual Studio create .AppHost and .ServiceDefault projects alongside your selected project template.
:::image type="content" source="../media/aspire-enlist-orchestration.png" lightbox="../media/aspire-enlist-orchestration.png" alt-text="A screenshot showing how to enlist in .NET Aspire orchestration.":::