Edit

Share via


Aspire templates

There are a number of Aspire project templates available to you. You can use these templates to create full Aspire solutions, or add individual projects to existing Aspire solutions.

The Aspire templates are available in the 📦 Aspire.ProjectTemplates NuGet package.

Available templates

The Aspire templates allow you to create new apps pre-configured with the Aspire solutions structure and default settings. These projects also provide a unified debugging experience across the different resources of your app.

Aspire templates are available in two categories: solution templates and project templates. Solution templates create a new Aspire solution with multiple projects, while project templates create individual projects that can be added to an existing Aspire solution.

Solution templates

The following Aspire solution templates are available, assume the solution is named AspireSample:

Project templates

The following Aspire project templates are available:

  • Aspire AppHost: A standalone .AppHost project that can be used to orchestrate and manage the different projects and services of your app.

  • Aspire Test projects: These project templates are used to create test projects for your Aspire app, and they're intended to represent functional and integration tests. The test projects include the following templates:

    • MSTest: A project that contains MSTest integration of an Aspire AppHost project.
    • NUnit: A project that contains NUnit integration of an Aspire AppHost project.
    • xUnit: A project that contains xUnit.net integration of an Aspire AppHost project.

    For more information on the test templates, see Testing in Aspire.

  • 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.

    Important

    The service defaults project template takes a FrameworkReference dependency on Microsoft.AspNetCore.App. This may not be ideal for some project types. For more information, see Aspire service defaults.

Install the Aspire templates

To install the Aspire templates in Visual Studio, you need to manually install them unless you're using Visual Studio 17.12 or later. For Visual Studio 17.9 to 17.11, follow these steps:

  1. Open Visual Studio.
  2. Go to Tools > NuGet Package Manager > Package Manager Console.
  3. Run the following command to install the templates:
dotnet new install Aspire.ProjectTemplates

For Visual Studio 17.12 or later, the Aspire templates are installed automatically.

To install these templates, use the dotnet new install command, passing in the Aspire.ProjectTemplates NuGet identifier.

dotnet new install Aspire.ProjectTemplates

To install a specific version, append the version number to the package name:

dotnet new install Aspire.ProjectTemplates::9.4.0

Create solutions and projects using templates

To create an Aspire solution or project, use Visual Studio, Visual Studio Code, or the .NET CLI, and base it on the available templates. Explore additional Aspire templates in the Aspire samples repository.

To create an Aspire project using Visual Studio, search for Aspire in the Visual Studio new project window and select your desired template.

Visual Studio: Aspire templates.

Follow the prompts to configure your project or solution from the template, and then select Create.

To create an Aspire project using Visual Studio Code, search for Aspire in the Visual Studio Code new project window and select your desired template.

Visual Studio Code: Aspire templates.

Select the desired ___location, enter a name, and select Create.

To create an Aspire solution or project using the .NET CLI, use the dotnet new command and specify which template you would like to create. Consider the following examples:

To create a basic Aspire AppHost project targeting the latest .NET version:

dotnet new aspire-apphost

To create an Aspire starter app, which is a full solution with a sample UI and backing API included:

dotnet new aspire-starter

Tip

Aspire templates default to using the latest .NET version, even when using an earlier version of the .NET CLI. To manually specify the .NET version, use the --framework <tfm> option, e.g. to create a basic Aspire AppHost project targeting .NET 8:

dotnet new aspire-apphost --framework net8.0

You need to trust the ASP.NET Core localhost certificate before running the app. Run the following command:

dotnet dev-certs https --trust

For more information, see Troubleshoot untrusted localhost certificate in Aspire. For in-depth details about troubleshooting localhost certificates on Linux, see ASP.NET Core: GitHub repository issue #32842.

See also