Commit d45cbb3
Platform specific docs analyzer (#128411)
## Add PlatformDocAnalyzer to enforce consistent documentation across
platform-specific builds
When a library uses `UseCompilerGeneratedDocXmlFile=true` (the default)
and targets platform-specific TFMs like `net11.0-windows`, only one
platform's compiler-generated doc XML is shipped to customers in the
IntelliSense package. If XML doc comments are placed on
platform-specific partial source files, they may be missing or
inconsistent on other platforms.
This PR adds a Roslyn analyzer (`eng/analyzers/PlatformDocAnalyzer`)
that enforces documentation placement conventions and validates doc
consistency. It only activates for platform-specific TFMs with
`UseCompilerGeneratedDocXmlFile=true`.
### Diagnostics
| ID | Severity | Description |
|----|----------|-------------|
| PLATDOC001 | Warning | Public type has no source file named
`TypeName.cs`. |
| PLATDOC002 | Warning | Partial source file doesn't follow the
`TypeName.Something.cs` naming convention. |
| PLATDOC003 | Warning | Public member in a non-primary partial file has
XML doc comments that should be moved to `TypeName.cs`. |
| PLATDOC004 | Warning | Documentation for a public API differs from the
canonical (platform-agnostic) build. |
PLATDOC001–003 are heuristic rules that guide source organization for
partial types split across multiple files. PLATDOC004 is the
authoritative check: when a project also targets a platform-agnostic TFM
(e.g. `net11.0` alongside `net11.0-windows`), the build locates the
canonical TFM's compiler-generated doc XML and passes it to the analyzer
as an `AdditionalFile`. The analyzer then compares each public API's
documentation against the canonical version and reports mismatches.
### Build integration
- **`eng/intellisense.targets`** — For platform-specific TFMs, derives
the canonical TFM by stripping the platform suffix (e.g.
`net11.0-windows` → `net11.0`) and passes its doc XML as an
`AdditionalFile` if available. Uses the artifact path directly rather
than a `ProjectReference` to avoid circular dependencies with PNSE
builds.
- **`eng/generators.targets`** — Wires the analyzer into all
`IsSourceProject` C# builds.
- **`eng/analyzers/PlatformDocAnalyzer/PlatformDocAnalyzer.props`** —
Declares `CompilerVisibleProperty` and `CompilerVisibleItemMetadata` for
the analyzer to read MSBuild context.
### Suppressions
Added `#pragma warning disable` in 5 System.Private.Xml files that use
established non-platform-specific patterns (`TypeNameAsync.cs` for async
partials, `XmlResolver.FileSystemResolver.cs` / `ThrowingResolver.cs`
for nested-type-adjacent properties).
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 444d544 commit d45cbb3
15 files changed
Lines changed: 1141 additions & 50 deletions
File tree
- docs/coding-guidelines
- eng
- analyzers
- PlatformDocAnalyzer.Tests
- PlatformDocAnalyzer
- src/libraries/System.Private.Xml/src/System/Xml
- Core
- Resolvers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
61 | 103 | | |
62 | 104 | | |
63 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
0 commit comments