dotnet-xml-docs
XML documentation comments for .NET: all standard tags (<summary>, <param>, <returns>, <exception>, <remarks>,
<example>, <value>, <typeparam>, <typeparamref>, <paramref>), advanced tags (<inheritdoc> for interface and
base class inheritance, <see cref="..."/>, <seealso>, <c> and <code>), enabling XML doc generation with
<GenerateDocumentationFile> MSBuild property, warning suppression strategies for internal APIs (CS1591, <NoWarn>,
InternalsVisibleTo), XML doc conventions for public NuGet libraries, auto-generation tooling (IDE quick-fix ///
trigger, GhostDoc-style patterns), and IntelliSense integration showing XML docs in IDE tooltips and autocomplete.
Version assumptions: .NET 8.0+ baseline. XML documentation comments are a C# language feature available in all .NET
versions. <GenerateDocumentationFile> MSBuild property works with .NET SDK 6+. <inheritdoc> fully supported since C#
9.0 / .NET 5+.
Scope
- Standard XML doc tags (summary, param, returns, exception, remarks, example)
- Advanced tags (inheritdoc, see cref, seealso, c, code)
- GenerateDocumentationFile MSBuild configuration
- Warning suppression strategies for internal APIs (CS1591)
- Conventions for public NuGet library documentation
Out of scope
- API documentation site generation (DocFX, Starlight) -- see [skill:dotnet-api-docs]
- General C# coding conventions and naming standards -- see [skill:dotnet-csharp-coding-standards]
- CI/CD deployment of documentation sites -- see [skill:dotnet-gha-deploy]
Cross-references: [skill:dotnet-api-docs] for downstream API documentation generation from XML comments,
[skill:dotnet-csharp-coding-standards] for general C# coding conventions, [skill:dotnet-gha-deploy] for doc site
deployment.
Enabling XML Documentation Generation
MSBuild Configuration
Enable XML documentation file generation in the project or Directory.Build.props:
<!-- In .csproj or Directory.Build.props -->
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
```csharp
This generates a `.xml` file alongside the assembly during build (e.g., `MyLibrary.xml` next to `MyLibrary.dll`). NuGet pack automatically includes this XML file in the package, enabling IntelliSense for package consumers.
### Warning Suppression for Internal APIs
When `GenerateDocumentationFile` is enabled, the compiler emits CS1591 warnings for all public members missing XML doc comments. Suppress warnings selectively for internal-facing code:
**Option 1: Suppress globally for the entire project (not recommended for public libraries):**
```xml
<PropertyGroup>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
```xml
**Option 2: Suppress per-file with pragma directives (recommended for mixed-visibility assemblies):**
```csharp
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
// TODO: Audit suppression - add justification or remove
public class InternalServiceHelper
{
// This type is internal-facing despite being public
// (e.g., exposed for testing via InternalsVisibleTo)
}
#pragma warning restore CS1591
```text
**Option 3: Use `InternalsVisibleTo` and keep internal types truly internal:**
```csharp
// In AssemblyInfo.cs or a Properties file
[assembly: InternalsVisibleTo("MyLibrary.Tests")]
```csharp
```csharp
// Mark internal-facing types as internal instead of public
internal class ServiceHelper
{
// No CS1591 warning -- internal types are not documented
}
```text
**Option 4: Treat missing docs as errors for public libraries (strictest):**
```xml
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Treat missing XML docs as build errors -->
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors>
</PropertyGroup>
```xml
This forces documentation for every public member. Use this for NuGet packages where consumers depend on IntelliSense documentation.
---
For complete tag examples (summary, param, returns, exception, remarks, example, inheritdoc, see/seealso, comprehensive class example, library conventions), see `examples.md` in this skill directory.
## Agent Gotchas
1. **Always enable `<GenerateDocumentationFile>` for public libraries** -- without it, NuGet consumers get no IntelliSense documentation. Add it to `Directory.Build.props` to apply across all projects in a solution.
1. **Use `<inheritdoc />` for interface implementations and overrides** -- do not duplicate documentation text between an interface and its implementation. Duplication causes maintenance drift.
1. **Do not suppress CS1591 globally for public NuGet packages** -- global suppression via `<NoWarn>CS1591</NoWarn>` hides all missing documentation warnings. Use per-file `#pragma` suppression for intentionally undocumented types, or make internal types truly `internal`.
1. **Use `<see cref="..."/>` for all type references, not bare type names** -- `<see cref="Widget"/>` enables IDE navigation and is validated at build time. Bare text "Widget" is not linked and can become stale if the type is renamed.
1. **Use `<see langword="null"/>` instead of bare `null` in documentation text** -- this renders with proper formatting in IntelliSense and API doc sites. Same applies to `true`, `false`, and other C# keywords.
1. **`<inheritdoc>` resolves at build time, not design time** -- some older IDE versions may show "Documentation not found" for `<inheritdoc>` in tooltips. The documentation is correctly resolved in the generated XML file and in API doc sites.
1. **XML doc comments must use `<` and `>` for generic type syntax in prose** -- but `<see cref="..."/>` handles generics automatically. Use `<see cref="List{T}"/>` (curly braces), not `<see cref="List<T>"/>`.
1. **In `<code>` blocks, use `<` and `>` for angle brackets** -- XML doc comments are XML, so `<` and `>` in code examples must be escaped. Alternatively, use `<![CDATA[...]]>` to avoid escaping.
1. **Do not generate API documentation sites from XML comments** -- API doc site generation (DocFX, OpenAPI-as-docs) belongs to [skill:dotnet-api-docs]. This skill covers the XML comment authoring side only.
1. **Document cancellation tokens with a single standard line** -- use "A token to cancel the asynchronous operation." for all `CancellationToken` parameters. Do not over-document the cancellation pattern.
Code Navigation (Serena MCP)
Primary approach: Use Serena symbol operations for efficient code navigation:
- Find definitions:
serena_find_symbol instead of text search
- Understand structure:
serena_get_symbols_overview for file organization
- Track references:
serena_find_referencing_symbols for impact analysis
- Precise edits:
serena_replace_symbol_body for clean modifications
When to use Serena vs traditional tools:
- Use Serena: Navigation, refactoring, dependency analysis, precise edits
- Use Read/Grep: Reading full files, pattern matching, simple text operations
- Fallback: If Serena unavailable, traditional tools work fine
Example workflow:
# Instead of:
Read: src/Services/OrderService.cs
Grep: "public void ProcessOrder"
# Use:
serena_find_symbol: "OrderService/ProcessOrder"
serena_get_symbols_overview: "src/Services/OrderService.cs"
1---2name: dotnet-xml-docs3category: developer-experience4subcategory: docs5description: Writes XML doc comments. Tags, inheritdoc, GenerateDocumentationFile, warning suppression.6license: MIT7targets: ['*']8tags: [foundation, dotnet, skill]9version: '0.0.1'10author: 'dotnet-agent-harness'11invocable: true12claudecode:13 allowed-tools: ['Read', 'Grep', 'Glob', 'Bash', 'Write', 'Edit']14codexcli:15 short-description: '.NET skill guidance for foundation tasks'16opencode:17 allowed-tools: ['Read', 'Grep', 'Glob', 'Bash', 'Write', 'Edit']18copilot: {}19geminicli: {}20antigravity: {}21---2223# dotnet-xml-docs2425XML documentation comments for .NET: all standard tags (`<summary>`, `<param>`, `<returns>`, `<exception>`, `<remarks>`,26`<example>`, `<value>`, `<typeparam>`, `<typeparamref>`, `<paramref>`), advanced tags (`<inheritdoc>` for interface and27base class inheritance, `<see cref="..."/>`, `<seealso>`, `<c>` and `<code>`), enabling XML doc generation with28`<GenerateDocumentationFile>` MSBuild property, warning suppression strategies for internal APIs (`CS1591`, `<NoWarn>`,29`InternalsVisibleTo`), XML doc conventions for public NuGet libraries, auto-generation tooling (IDE quick-fix `///`30trigger, GhostDoc-style patterns), and IntelliSense integration showing XML docs in IDE tooltips and autocomplete.3132**Version assumptions:** .NET 8.0+ baseline. XML documentation comments are a C# language feature available in all .NET33versions. `<GenerateDocumentationFile>` MSBuild property works with .NET SDK 6+. `<inheritdoc>` fully supported since C#349.0 / .NET 5+.3536## Scope3738- Standard XML doc tags (summary, param, returns, exception, remarks, example)39- Advanced tags (inheritdoc, see cref, seealso, c, code)40- GenerateDocumentationFile MSBuild configuration41- Warning suppression strategies for internal APIs (CS1591)42- Conventions for public NuGet library documentation4344## Out of scope4546- API documentation site generation (DocFX, Starlight) -- see [skill:dotnet-api-docs]47- General C# coding conventions and naming standards -- see [skill:dotnet-csharp-coding-standards]48- CI/CD deployment of documentation sites -- see [skill:dotnet-gha-deploy]4950Cross-references: [skill:dotnet-api-docs] for downstream API documentation generation from XML comments,51[skill:dotnet-csharp-coding-standards] for general C# coding conventions, [skill:dotnet-gha-deploy] for doc site52deployment.5354---5556## Enabling XML Documentation Generation5758### MSBuild Configuration5960Enable XML documentation file generation in the project or `Directory.Build.props`:6162````xml6364<!-- In .csproj or Directory.Build.props -->65<PropertyGroup>66 <GenerateDocumentationFile>true</GenerateDocumentationFile>67</PropertyGroup>6869```csharp7071This generates a `.xml` file alongside the assembly during build (e.g., `MyLibrary.xml` next to `MyLibrary.dll`). NuGet pack automatically includes this XML file in the package, enabling IntelliSense for package consumers.7273### Warning Suppression for Internal APIs7475When `GenerateDocumentationFile` is enabled, the compiler emits CS1591 warnings for all public members missing XML doc comments. Suppress warnings selectively for internal-facing code:7677**Option 1: Suppress globally for the entire project (not recommended for public libraries):**7879```xml8081<PropertyGroup>82 <NoWarn>$(NoWarn);CS1591</NoWarn>83</PropertyGroup>8485```xml8687**Option 2: Suppress per-file with pragma directives (recommended for mixed-visibility assemblies):**8889```csharp9091#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member92// TODO: Audit suppression - add justification or remove93public class InternalServiceHelper94{95 // This type is internal-facing despite being public96 // (e.g., exposed for testing via InternalsVisibleTo)97}98#pragma warning restore CS159199100```text101102**Option 3: Use `InternalsVisibleTo` and keep internal types truly internal:**103104```csharp105106// In AssemblyInfo.cs or a Properties file107[assembly: InternalsVisibleTo("MyLibrary.Tests")]108109```csharp110111```csharp112113// Mark internal-facing types as internal instead of public114internal class ServiceHelper115{116 // No CS1591 warning -- internal types are not documented117}118119```text120121**Option 4: Treat missing docs as errors for public libraries (strictest):**122123```xml124125<PropertyGroup>126 <GenerateDocumentationFile>true</GenerateDocumentationFile>127 <!-- Treat missing XML docs as build errors -->128 <WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors>129</PropertyGroup>130131```xml132133This forces documentation for every public member. Use this for NuGet packages where consumers depend on IntelliSense documentation.134135---136137138For complete tag examples (summary, param, returns, exception, remarks, example, inheritdoc, see/seealso, comprehensive class example, library conventions), see `examples.md` in this skill directory.139140## Agent Gotchas1411421. **Always enable `<GenerateDocumentationFile>` for public libraries** -- without it, NuGet consumers get no IntelliSense documentation. Add it to `Directory.Build.props` to apply across all projects in a solution.1431441. **Use `<inheritdoc />` for interface implementations and overrides** -- do not duplicate documentation text between an interface and its implementation. Duplication causes maintenance drift.1451461. **Do not suppress CS1591 globally for public NuGet packages** -- global suppression via `<NoWarn>CS1591</NoWarn>` hides all missing documentation warnings. Use per-file `#pragma` suppression for intentionally undocumented types, or make internal types truly `internal`.1471481. **Use `<see cref="..."/>` for all type references, not bare type names** -- `<see cref="Widget"/>` enables IDE navigation and is validated at build time. Bare text "Widget" is not linked and can become stale if the type is renamed.1491501. **Use `<see langword="null"/>` instead of bare `null` in documentation text** -- this renders with proper formatting in IntelliSense and API doc sites. Same applies to `true`, `false`, and other C# keywords.1511521. **`<inheritdoc>` resolves at build time, not design time** -- some older IDE versions may show "Documentation not found" for `<inheritdoc>` in tooltips. The documentation is correctly resolved in the generated XML file and in API doc sites.1531541. **XML doc comments must use `<` and `>` for generic type syntax in prose** -- but `<see cref="..."/>` handles generics automatically. Use `<see cref="List{T}"/>` (curly braces), not `<see cref="List<T>"/>`.1551561. **In `<code>` blocks, use `<` and `>` for angle brackets** -- XML doc comments are XML, so `<` and `>` in code examples must be escaped. Alternatively, use `<![CDATA[...]]>` to avoid escaping.1571581. **Do not generate API documentation sites from XML comments** -- API doc site generation (DocFX, OpenAPI-as-docs) belongs to [skill:dotnet-api-docs]. This skill covers the XML comment authoring side only.1591601. **Document cancellation tokens with a single standard line** -- use "A token to cancel the asynchronous operation." for all `CancellationToken` parameters. Do not over-document the cancellation pattern.161````162163## Code Navigation (Serena MCP)164165**Primary approach:** Use Serena symbol operations for efficient code navigation:1661671. **Find definitions**: `serena_find_symbol` instead of text search1682. **Understand structure**: `serena_get_symbols_overview` for file organization1693. **Track references**: `serena_find_referencing_symbols` for impact analysis1704. **Precise edits**: `serena_replace_symbol_body` for clean modifications171172**When to use Serena vs traditional tools:**173174- **Use Serena**: Navigation, refactoring, dependency analysis, precise edits175- **Use Read/Grep**: Reading full files, pattern matching, simple text operations176- **Fallback**: If Serena unavailable, traditional tools work fine177178**Example workflow:**179180```text181# Instead of:182Read: src/Services/OrderService.cs183Grep: "public void ProcessOrder"184185# Use:186serena_find_symbol: "OrderService/ProcessOrder"187serena_get_symbols_overview: "src/Services/OrderService.cs"188```