DEV Community

Pramesh Kc.
Pramesh Kc.

Posted on

Discovering the Gem in .NET 8: Introducing ".NET Aspire"

This year, Microsoft rolled out a game-changer in the .NET 8 lineup – ".NET Aspire." As a developer, this has quickly become my absolute favorite feature.

We'll delve into the essentials of ".NET Aspire" and walk through the installation steps to get it up and running on your development environment. From there, we'll fire up a new project, leveraging the power and flexibility that ".NET Aspire" brings to the table.

Image description
What is .net Aspire?
Imagine a toolkit designed specifically for crafting cloud-ready, distributed applications. That's exactly what .NET Aspire brings to the table. It's not just a set of tools; it's a cloud-native stack delivered through NuGet packages, addressing key concerns in modern application development.

The beauty of .NET Aspire lies in its compatibility with the microservices approach. If you're into building applications with smaller, interconnected components, this is your golden ticket. Cloud-native apps, leveraging .NET Aspire, seamlessly consume various services like databases, messaging, and caching.

**Before we dive into the world of ".NET Aspire," let's make sure you're all set. Here's your checklist:

.NET 8 Installed: It's like the superhero suit for your development adventures. Make sure you have .NET 8 ready to roll on your machine.

.NET Aspire Workload:
CLI to install .net aspire



dotnet workload update
// to make sure latest .net aspire installed


Enter fullscreen mode Exit fullscreen mode


dotnet workload install aspire
//This brings all the magic to your development world.


Enter fullscreen mode Exit fullscreen mode


dotnet workload list
//check current aspire version


Enter fullscreen mode Exit fullscreen mode

IDE or Code Editor: Choose your weapon! While it's optional, having a good Integrated Developer Environment (IDE) or code editor enhances the experience. You can go with Visual Studio 2022 Preview version 17.9 or higher for the full superhero vibe. If you're more of a minimalist, Visual Studio Code works like a charm too.
Docker Desktop:
For that extra oomph in containerized magic, grab "Docker Desktop."

Launching Your First .NET Aspire Project: Easy-Peasy Steps!

Ready to dip your toes into the world of ".NET Aspire"? Let's create your very own project with these simple commands:

Basic .NET Aspire Project:
If you're starting fresh, use this magic line:



dotnet new aspire --name dotnet8Aspire



Enter fullscreen mode Exit fullscreen mode

This sets up a basic ".NET Aspire" project for you – like a blank canvas waiting for your code masterpiece.

Fancy .NET Aspire Project (with UI and API):
Feeling a bit adventurous? Try this one:



dotnet new aspire-starter


Enter fullscreen mode Exit fullscreen mode

This not only creates a ".NET Aspire" project but also throws in a sample UI and API.

I'm creating basic .net aspire project with out UI and API, I'll add project later.

Image description

With the simple command dotnet new aspire, you're getting a no-frills ".NET Aspire" app. What's inside? Just two main things:

AppHost: The Maestro of Your App
The AppHost is like the chief conductor of your app orchestra. It rounds up all your projects, builds them, and sets the stage for your application. Imagine it as the leader making sure everyone plays in harmony. As you add more projects, AppHost takes care of the coordination, handling dependencies, NuGet files, and resolving connections – making your life easier.

Image description

ServiceDefaults: The Powerhouse of Aspire
Meet ServiceDefaults the powerhouse of Aspire. It's like a pre-loaded magic box for your app. Telemetry, logging, metrics, analytics – it's all set up without you lifting a finger. Microsoft gives you a default set of tools, but hey, feel free to tweak, add, or remove as you please. It's your app, your rules! 🎉💻✨

Image description

Let's run the project

Image description

running on port http://localhost:18888

Image description

Dasboard for .net aspire simple project. Since we've added any project so it's saying no project found on project list.
Lets add simple API project on this aspire project.

Image description

Image description

I've created a simple asp.net core web api project with name dotnet8Aspire.API

Image description

Let's add API project to aspire. Since i've not install vs tools for visual studio through which we can enable aspire support for projects with Visual studio with just couple of click. So I'll manually add project to aspire.

Image description

API project reference is added on aspire project , now let's configure on appHost program.cs.

Image description

When we add reference of other projects on aspire , all the added projects will available inside namespace "projects"

On API project "dotnet8Aspire.API" add reference of ServiceDefaults project and register AddServiceDefault on program.cs.

Image description

Now Lets run the project again

Image description

as we can see there's our newly added project on dashbaord. We can run the projects from here, view logs, enviroment variables and so on.

Image description

API project is running on http://localhost:5244. By regsitering on AppHost (aspire) we don't have to manually run API project, all the things are taken care from appHost.

let's send request from API and see logs from dashboard http://localhost:5244

Image description

I've execute one endpoint of API , now let's see on dashboard if there's any logs available from this current request.

Image description

And there you have it – a simple sneak peek into the world of ".NET Aspire." This was just the tip of the iceberg, a basic intro to get your feet wet. I hope you found it helpful and maybe learned a thing or two.
There's so much more to explore in the realm of .NET Aspire. So buckle up, stay curious, and keep an eye out for the next tutorial where we'll dive even deeper into the wonders of .NET Aspire. Until then, happy coding, and may your apps aspire to greatness! 💻🚀🌟

Top comments (0)