If you’ve recently created a .NET 9 Web API project and noticed that Swagger UI is not opening by default, you’re not alone.

Many developers upgrading from earlier versions of ASP.NET Core are surprised by this behavior.

In this blog post, we’ll cover:

The Problem Occurs when creating API project in .NET 9

After creating a new .NET 9 Web API project, you may experience:

This happens even in Development mode, which can be confusing if you’re used to older .NET versions.

Why Swagger Is Missing in .NET 9

Starting with .NET 9, Microsoft removed Swagger from the default Web API project template.

Why did Microsoft do this?

Swagger is now considered an optional development tool, not something every API needs out of the box.

How to Enable Swagger in .NET 9 (Step-by-Step)

The fix is straightforward. You just need to add Swagger explicitly.

Step 1: Install Swagger NuGet Package

Run the following command in your project directory:

dotnet add package Swashbuckle.AspNetCore

This package provides:

Step 2: Configure Swagger in Program.cs

Open Program.cs and update it as shown below:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container
builder.Services.AddControllers();

// Add Swagger services
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Enable Swagger only in Development environment
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

Step 3: Run the Application

Start your application:

dotnet run

Then open your browser and navigate to:

<https://localhost>:<port>/swagger

Swagger UI should now be visible and fully functional.

Optional: Open Swagger Automatically on Launch

If you want Swagger to open automatically when the app starts:

Visual Studio Users

  1. Open launchSettings.json

  2. Set the launchUrl to swagger

"launchBrowser": true,
"launchUrl": "swagger"

Common Mistakes Developers Make

Best Practices for Swagger in .NET APIs

Conclusion

.NET 9 introduces a more minimal and intentional project template. While Swagger is no longer enabled by default, re-adding it takes only a few lines of code and gives you full control over when and how it’s used. Swagger remains an essential tool for API documentation ,Endpoint testing and Improves developer experience .

I hope this article helped you clearly understand why Swagger is missing in .NET 9 and how to resolve it effectively.