Skip to content

Instantly share code, notes, and snippets.

@cantis
Created January 25, 2023 17:05
Show Gist options
  • Save cantis/62efc113fbee78c59394edc98ad29421 to your computer and use it in GitHub Desktop.
Save cantis/62efc113fbee78c59394edc98ad29421 to your computer and use it in GitHub Desktop.
Notes on writing C# APIs

API Documentation: Generation from XML Comments

Note: This applies to .net 6 LTS

  1. Turn on XML Documentation generation in the project in Properties-Build-Output select Documentation File
  2. Modify the AddSwaggerGen line in the program.cs file
builder.Services.AddSwaggerGen( c =>
    c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory,
        $"{Assembly.GetExecutingAssembly().GetName().Name}.xml")));

Note: This assumes that you are creating the xml documentation file in the default location and picking it up from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment