During local development, my ASP.NET Core 8 Minimal API project is operating without any issues. Swagger opens at /swagger, all endpoints are visible, and everything is testable directly from the user interface when I run the application using dotnet run
or directly in Visual Studio.
After publishing, the issue arises. I've attempted using Kestrel to deploy both to IIS and as a stand-alone application. Swagger loads in both scenarios, but none of the endpoints are visible. The user interface is totally blank. The strange thing is that if I hit the endpoints directly in the browser, such as /api/health
, they still react. Swagger simply isn't picking up anything, even though the app itself is obviously running.
Please see my Program.cs
setup:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapGet("/api/health", () => Results.Ok("Healthy"));
app.Run();
I also tried to set up Swagger like this:
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
Still, no changes after publishing.
This works perfectly locally. However, Swagger loads without any errors and only without endpoints after publishing. Has there been any changes with the way minimal APIs register with Swagger in.NET 8 in any way? Or am I overlooking a straightforward step in the publishing process?
Please advise me.
I ran into the exact same issue recently. Swagger loaded fine but no endpoints showed after publishing.
Deleting the bin
and obj
folders before republishing fixed it for me.
Seems like stale builds can cause this kind of weird behavior.