Swagger configuration

Two steps that i needed for this in .NET 6.

Add this to program.cs file;

// Register swagger generator, you can define multiple documents here
services.AddSwaggerGen(s =>
	s.SwaggerDoc("v1", new OpenApiInfo
		Title = "FOO API",
		Version = "v1"

	var xmlFile = $"{typeof(Presentation.AssemblyReference).Assembly.GetName().Name}.xml";
	var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);

Edit project .csproj file and add / change these nodes:


    Make sure documentation XML is also included when publishing (not only when testing)
    see https://github.com/Azure/service-fabric-issues/issues/190

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

This also works with .NET Core 3.1. more info can be found here.

FavoriteLoadingAdd to favorites
Spread the love

Author: Shahzad Khan

Software developer / Architect