Get Started: Building Your Initial .NET Aspire App
Creating a .NET Aspire Starter Application for Efficient Cloud-Native Development
Cloud-native applications often necessitate connections to diverse services like databases, storage solutions, messaging platforms, or web services. .NET Aspire simplifies these connections and configurations, facilitating streamlined development processes. This quickstart tutorial demonstrates how to initiate a .NET Aspire Starter Application template solution.
Objectives
Establish a fundamental .NET application configured to utilize .NET Aspire.
- Integrate and configure a .NET Aspire component to implement caching upon project creation.
- Develop an API and employ service discovery to establish connectivity.
- Coordinate communication between a front-end UI, a back-end API, and a local Redis cache.
Prerequisites
Before diving in, ensure the following prerequisites are met:
- .NET 8.0 installed locally.
.NET Aspire workload
- Install via Visual Studio installer.
- Use the dotnet workload install aspire command.
- Docker Desktop installed.
Creating the .NET Aspire Template
You can create a new .NET Aspire Starter Application using either Visual Studio or the .NET CLI.
Using Visual Studio
- Navigate to File > New > Project at the top of Visual Studio.
- In the dialogue window, search for “Aspire” and select “.NET Aspire Starter Application”. Proceed to the next step.
- Configure your new project by entering a Project Name (e.g., “AspireSample”) and leave other values at their defaults. Proceed to the next step.
- Ensure that .NET 8.0 (Long Term Support) is selected and check “Use Redis for caching (requires Docker)”. Finally, select “Create” to finalize.
Testing the App Locally
Once the sample app is created, it’s ready for testing. Verify the following:
- Weather data is fetched from the API project via service discovery and displayed on the weather page.
- Subsequent requests are handled via the output caching configured by the .NET Aspire Redis component.
To run the app locally
- Set the AspireSample.AppHost project as the startup project in Visual Studio.
- Press F5 to run the app.
- Navigate to the weather page from the home page in your browser to load weather data.
- Continuously refresh the page for 10 seconds to observe cached data retrieval.
To create a new .NET Aspire Starter Application template via the command line:
Open your command line interface & execute the following command:
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::5.0.0-preview.8.20414.8This command installs the .NET Aspire template for you to utilize.
Once the installation is complete, create a new .NET Aspire Starter Application by executing:
dotnet new aspire -n AspireSampleThis command creates a new project named “AspireSample” using the .NET Aspire template.
Testing the App Locally:
After creating the sample app, proceed to test it locally. Navigate to the project directory using the following command.
cd AspireSampleRun the app
dotnet run
Access the app through your web browser to ensure it functions as expected.
🤓 Congratulations! You’ve successfully created and tested your first .NET Aspire application.
More articles
Follow me on
C# Publication, LinkedIn, Instagram, Twitter, Dev.to







