liveBook · Manning

XML documentation file

As explained in Building Web APIs with ASP.NET Core

An XML documentation file is a compiler-generated file containing structured documentation extracted from specially formatted source-code comments.

An XML documentation file is a compiler-generated collection of structured descriptions extracted from triple-slash XML comments in C# source code. Swashbuckle can read it and display endpoint, parameter, and return-value explanations in SwaggerUI. section 11.2.2 section 11.2.3

Enable XML documentation for an API with these implementation steps:

  • Add triple-slash comments above action methods, including <summary>, <param>, and <returns> elements. section 11.2.3
  • Set GenerateDocumentationFile to true in the project file so the compiler creates an XML file during every build. section 11.2.3
  • Choose whether to suppress CS1591 warnings for undocumented public types and members with the NoWarn project setting. section 11.2.3
  • Configure Swashbuckle to derive the XML filename from the assembly and combine it with the application base directory. section 11.2.3
// ... existing code
 
<ItemGroup>
  <Protobuf Include="gRPC/grpc.proto" />
</ItemGroup>
 
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
 
// ... existing code

Use the project-file configuration to generate the XML documentation artifact. section 11.2.3

using System.Reflection;                                        #1
 
// ... existing code
 
builder.Services.AddSwaggerGen(options =>
{
var xmlFilename =                          #2
$"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(System.IO.Path.Combine(          #3
AppContext.BaseDirectory, xmlFilename));
 
    // ... existing code

Use the assembly name and application base directory to let Swashbuckle locate the generated file. section 11.2.3

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains comments, project settings, warning suppression, and Swashbuckle file discovery, but defers detailed XML schema behavior.
Examples
Uses Register and Login endpoint comments, a .csproj configuration, and generated SwaggerUI descriptions.
What it assumes
Assumes basic C# action methods, Visual Studio project editing, and existing SwaggerUI or Swashbuckle configuration.
What you can do after
Configure Swashbuckle to generate and display API descriptions from source-code comments.
How it connects
Connects C# XML comments with the .NET compiler, Swashbuckle, SwaggerUI, project files, and Reflection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.