Repository navigation
Conversation
Validated against the real linq2db docs buildTested on This found a real design gap, fixed in a8be8caAn assembly-name-keyed map cannot express the most common form of this problem. linq2db ships four All four ( So the PR now has two options with distinct jobs, both needed in general:
Result: equivalent metadata, substantially more correct siteBoth builds were run from source at Roslyn 5.6.0 for an apples-to-apples comparison. All 2389
Three concrete bugs in the hack that this PR's consistency fixes eliminate: 1. Malformed # hack
commentId: linq2db.T:LinqToDB.AnalyticFunctions.IAggregateFunction`1
# this PR
commentId: T:linq2db.LinqToDB.AnalyticFunctions.IAggregateFunction`12. Dead namespace/type hrefs. This is the # hack: href: LinqToDB.html <- no such page
# this PR: href: linq2db.LinqToDB.html <- the page that exists3. 1197 dead in-page anchors. Same root cause. The hack generated member anchors unprefixed The 2 extra
|
uidPrefixes to disambiguate assemblies sharing namespacesuidPrefix/uidPrefixes)
uidPrefix/uidPrefixes)assemblyUidPrefixes/uidPrefix)
assemblyUidPrefixes/uidPrefix)uidPrefix)
uidPrefix)assemblyUidPrefixes)
…x build (#64) * docs: fix cross reference and duplicate assembly issues, refresh docfx build Replaces the `globalPrefix` hack in the vendored docfx build with the `uidPrefix`/`uidPrefixes` options proposed upstream (MaceWindu/docfx#2, for dotnet/docfx#8966), and fixes the issues that surfaced once docfx started reporting them honestly. Site build goes from 1302 warnings to 67, with no change in generated page count (2389 API files): InvalidBookmark 1197 -> 1 dead in-page anchors Ignore duplicated member 28 -> 0 F# assembly loaded once per target framework InvalidAssemblyReference 5 -> 0 FSharp.Core not resolvable UidNotFound 0 -> 0 two stale article xrefs, fixed here The old build emitted a malformed `commentId` (`linq2db.T:LinqToDB...`, prefix before the kind marker), unprefixed namespace and type hrefs pointing at pages that do not exist, and ~1200 member anchors that did not match the bookmarks on their own pages. - source/docfx.json: `globalPrefix` -> `uidPrefix` on the four EntityFrameworkCore entries, which all build an assembly named `linq2db.EntityFrameworkCore` and so cannot be told apart by assembly name, plus a combined `uidPrefixes` map so references between entries resolve. - source/docfx.json: the F# entry globbed `Release/**/linq2db.FSharp.dll`, matching all five target framework folders, so the same assembly was loaded five times and every member reported duplicated. Pinned to netstandard2.0, with `references` pointing at the net462 output, the only one that carries FSharp.Core next to the assembly. - articles: `xref:LinqToDB.ProviderName` and `xref:LinqToDB.Data.BulkCopyOptions` now use the prefixed UIDs. These were silently broken before: the old build rendered a link to `LinqToDB.ProviderName.html`, which is not a page that exists. - docfx/: refreshed from custom/linq2db-uidprefix (d89a8f030) and documented in docfx/README.md. The 11 removed assemblies are transitive dependencies the newer Roslyn no longer ships. Remaining warnings all originate in the linq2db submodule and cannot be fixed here: 60 MSBuild duplicate-source-file warnings from the analyzer projects, 5 `InvalidFileLink` and 1 `InvalidBookmark` from XML documentation comments, and `No .NET API detected for linq2db.Compat`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: rename uidPrefixes to assemblyUidPrefixes, refresh docfx build Follows the option rename in the upstream PR: `uidPrefix`/`uidPrefixes` read as singular and plural of one concept while being scoped differently, so the map is now `assemblyUidPrefixes`, which says what its key is. - source/docfx.json: `uidPrefixes` -> `assemblyUidPrefixes`, and the comment now leads with the map since that is the primary option, with `uidPrefix` as the escape hatch for the four EntityFrameworkCore entries that share an assembly name. - docfx/: rebuilt from custom/linq2db-uidprefix (28070313a), which also picks up a fix for crefs being left unprefixed when only `uidPrefix` was set. Build output is unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages, no duplicate member, `UidNotFound` or `InvalidAssemblyReference` warnings. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: use the merged uidPrefix option, refresh docfx build Follows the upstream PR collapsing `assemblyUidPrefixes` and `uidPrefix` into a single `uidPrefix` that accepts either form, so the value shape says which scope applies: "uidPrefix": { "linq2db": "linq2db", ... } // by assembly name, shared by all entries "uidPrefix": "linq2db.EntityFrameworkCore.EF8" // this entry's own assemblies Both forms are still used here for the same reasons as before. Confirmed by measurement that the object form is not redundant: building with a string on every entry instead leaves 6690 cross-entry references into the core assembly, across 163 pages, pointing at UIDs no page has. They render as plain text with no link and no warning. docfx/ rebuilt from custom/linq2db-uidprefix (1d0b2de99). Build output unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: use assemblyUidPrefixes and uidPrefixOverride Follows the upstream PR splitting the merged option back into two names, since one name accepting a string or an object hid that the two forms have different scope. "assemblyUidPrefixes": { "linq2db": "linq2db", ... } // project wide, keyed by assembly name "uidPrefixOverride": "linq2db.EntityFrameworkCore.EF8" // this entry's own assemblies Same behaviour as before, and the config comment now says the map is project wide rather than merely "declared once here", which is what makes references between entries resolve. docfx/ rebuilt from custom/linq2db-uidprefix (5534e75af). Build output unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: move assemblyUidPrefixes to the project level Follows the upstream PR moving the map out of the metadata entries and up to the top level of docfx.json, next to `metadata`, where a project level setting belongs: { "assemblyUidPrefixes": { "linq2db": "linq2db", ... }, "metadata": [ ... ] } The comment now explains the selection rule rather than just the mechanics: every assembly appearing in another assembly's public signatures is listed, not only the ones whose namespaces collide, because a reference that comes out unprefixed loses its link with no warning. It also records why LinqToDB.Identity is absent, and why `uidPrefixOverride` is safe for the EF Core entries: nothing else in this project references those packages, so no other entry needs to name one of the four versions. docfx/ rebuilt from custom/linq2db-uidprefix (91955d98a). Build output unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
…mespaces A docfx UID is derived from the fully qualified name of an API alone, so when one docfx project documents several assemblies that declare the same namespace their APIs collide: `MergeMembers` drops or silently merges the duplicates, pages overwrite each other, `DuplicateUids` is reported, and every link to a shared namespace resolves to whichever assembly won. `uidPrefixes` maps an assembly name to a prefix that is prepended to the UID of every API declared in that assembly. The maps of all metadata items are combined before any of them is processed, so references between metadata items resolve regardless of the order they are declared in. Assemblies that are not listed are untouched, and the option is off by default, so generated output is unchanged unless it is configured. The prefix is applied in `VisitorHelper.GetDocumentationCommentId`, which covers uids, comment ids, overload ids, references, TOC nodes and file names. Three consumers needed to follow it explicitly: - `SymbolUrlResolver.GetDocfxUrl` builds hrefs from the raw Roslyn comment id while deriving file names through `VisitorHelper`. - crefs are resolved textually by `XmlComment`, with no symbol context, so a `ResolveUidPrefix` callback resolves the target through the compilation. - API filters keep matching the unprefixed API surface via `GetRawId`, so existing `filterConfig` files keep working when the option is enabled. Namespace display names include the prefix so that namespaces coming from different assemblies are distinguishable in the TOC, breadcrumbs and page titles, and so nested TOC parent trimming keeps matching. Fixes dotnet#8966 Fixes dotnet#9371 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Found while validating the fix against the linq2db docs build: an assembly name keyed map cannot express the most common form of this problem. linq2db ships four Entity Framework Core packages built from one shared props file, so all four produce an assembly named `linq2db.EntityFrameworkCore` and need four different prefixes. The same shape appears in any project with per target version builds. `uidPrefix` is a per metadata entry prefix that applies to the assemblies that entry documents and takes precedence over `uidPrefixes`. The entry's assemblies are only known after they are compiled, so it is assigned in `Build` right after `Compile`, and stays constant for the whole entry, which keeps it safe for the parallel API page generation to read. The two options have distinct jobs and both are needed in general: `uidPrefix` says how to prefix the APIs an entry documents, `uidPrefixes` says how to address APIs documented by another entry, whose `uidPrefix` is not visible from this one. Snapshot output remains byte identical when neither option is set. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ify the two options Review feedback: `uidPrefix`/`uidPrefixes` read as singular and plural of one concept, but they are scoped differently, which made the map hard to understand. `assemblyUidPrefixes` says what the key is and removes the false symmetry. Also reframes the docs around which option to reach for: - `assemblyUidPrefixes` is the primary option. It is presented first, and the reason it has to be a shared map rather than a per entry setting is now stated: an entry mints UIDs for the APIs it *references* as well as the ones it documents, and those must match the UIDs produced by the entry documenting them. - `uidPrefix` is documented as the narrow escape hatch for several entries building the same assembly name, with the trade-off spelled out (other entries cannot see it). - Drops the example that set both options for the same assembly, which stated the same thing twice. - Adds a table of which option applies when. Fixes a bug found while renaming: `GetUidPrefixForCommentId` returned early unless the map was populated, so crefs were left unprefixed when only `uidPrefix` was set. Both entry points now share an `IsUidPrefixConfigured` check, and a new test covers crefs under a per entry prefix. Snapshot output is byte identical to the previous commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: `assemblyUidPrefixes` and `uidPrefix` were an inconsistent pair of names for what is
one concept. There is now a single `uidPrefix` option that accepts either form, so the shape of the
value says which scope applies:
"uidPrefix": { "MyLib": "Core" } // by assembly name, shared by all metadata entries
"uidPrefix": "Ef8" // this entry's own assemblies
Both forms are still needed, and measuring on the linq2db docs build shows why. Replacing the object
form with a string on all 16 entries leaves cross-entry references unprefixed: 6690 references into the
core assembly across 163 pages resolve to UIDs no page has, so they render as plain text with no link
and no warning. The object form is combined across entries, which is what keeps those links alive; the
string form exists only because assemblies sharing an assembly name cannot be keyed by name.
`UidPrefixSetting` plus Newtonsoft and System.Text.Json converters follow the existing
`MarkdigExtensionSetting` pattern, so the value round trips as the bare string or object it was written
as. The JSON schema uses `oneOf`, and both forms are covered by the serialization parity test data and
by an end-to-end `MetadataCommandTest` case each.
Docs are restructured around the one option, with a subsection per form stating when to reach for it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…xOverride` Review feedback: one option accepting a string or an object hid the fact that the two forms have different scope. Two names make that visible, and `uidPrefixOverride` names its relationship to the map rather than being its singular, which is what made the earlier `uidPrefix`/`uidPrefixes` pair confusing. - `assemblyUidPrefixes` (map) is the option to reach for. It is project wide despite being written inside an entry: the maps of all entries are combined before any is processed. - `uidPrefixOverride` (string) overrides it for one entry's assemblies, and is needed only when several entries build the same assembly name. `UidPrefixSetting` and its two converters are gone with the merged option. Docs now answer where the map goes when a project has many `src` entries, which the previous wording left implicit: any entry works because the maps are combined, the whole map on the first entry is recommended because it reads as one table, and the reason a per entry setting cannot replace it is spelled out — an entry mints UIDs for the APIs it references as well as the ones it documents, and getting those wrong loses links with no warning. Adds the rule of thumb that any assembly referenced by another entry belongs in the map, and notes that conflicting mappings warn and keep the first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: the option was documented as project wide but written inside a `metadata` entry, which
put it out of place. It is now a top level `docfx.json` property, next to `metadata` and `rules`:
{
"assemblyUidPrefixes": { "MyLib": "Core" },
"metadata": [ ... ]
}
`DocfxConfig` carries it, `DotnetApiCatalog.Exec` takes it as an optional trailing parameter, and both
entry points pass it: the `docfx`/`docfx metadata` commands from `DocfxConfig`, and
`GenerateManagedReferenceYamlFiles` from the JSON it already parses itself. Validation splits into
`ValidateAssemblyUidPrefixes` for the project level map and `ValidateUidPrefixOverrides` for the per
entry overrides.
`uidPrefixOverride` stays on the entry, which is the point of it.
Docs now also state what the override does not fix, since that was not obvious:
- links from other entries into an override-prefixed assembly cannot be expressed, so it is only safe
for assemblies nothing else in the project references
- it does not disambiguate two same-named assemblies inside one entry, because every assembly an entry
documents gets the same prefix; narrowing the `src` glob is the fix there
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…grammar
Two review points.
**Default link target.** `uidPrefixOverride` cannot be seen by other entries, so references into an
assembly documented by several entries lose their links. No new option is needed for this: listing the
assembly in `assemblyUidPrefixes` as well already makes that prefix the fallback, because the override
only wins for the assemblies its own entry documents. So
"assemblyUidPrefixes": { "MyLib.Ef": "Ef9" }
alongside `uidPrefixOverride` on the Ef8 and Ef9 entries keeps both versions' pages while pointing every
other entry's references at Ef9. Covered by a new test and documented, including the limitation that all
such links go to one chosen version.
**Prefix grammar.** The pattern required every segment to be a C# style identifier, which was my
invention rather than a real constraint, and it rejected plausible prefixes such as `net8.0` or `v1.2`.
The real constraints come from the UID becoming a file name, an xref key and an HTML anchor. Segments
after the first may now start with a digit:
^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)*$
Still stricter than `globalNamespaceId`, which is inserted the same way and validates nothing at all, but
that strictness is deliberate: it keeps path and UID metacharacters out. The warning message now
describes the grammar instead of saying "identifier", and a test covers a digit leading segment.
Also adds the first coverage of the validation path itself: invalid map values, empty assembly names and
an invalid override are each reported as `InvalidUidPrefix` and dropped, and generation continues.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: the setup for pointing other entries at one of several same-named assemblies was buried as a fourth level subsection under a "what the override does not fix" caveat, so a reader with per version entries would not find it. It is now a top level section, "Nominate a default version for links from elsewhere", framed as a procedure rather than a caveat: - states up front that one version has to be nominated, and that it goes in `assemblyUidPrefixes` *in addition to* the per entry `uidPrefixOverride`, not instead of it - a table of which prefix is used when generating each thing, and why, so the composition of the two settings is explicit rather than asserted - guidance on which version to nominate, normally the newest supported - notes that hand written `<xref>` links are unaffected, since those name a UID literally The `uidPrefixOverride` reference entry now links here instead of repeating a partial version of the example. Verified in the generated site that the anchor exists and that both the in page link and the cross page link from the reference doc resolve to it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: `assemblyUidPrefixes` was appended after `cancellationToken`, which breaks the convention that a cancellation token is the last parameter. I had put it there to avoid touching existing call sites; correctness wins over the smaller diff. Only `MetadataCommand` passed both positionally and needed updating. The other call sites either stop before the optional parameters or already use `assemblyUidPrefixes:` by name. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
520a53a to
dd95c86
Compare
Replaces `assemblyUidPrefixes` / `uidPrefixOverride` with `assemblyUids` / `assemblyUidOverride`, which
join the assembly to the rest of the UID with `::` rather than a dot, and default the component to the
assembly's own name:
linq2db.Tools::LinqToDB.Tools.Activity.ActivityStatistics
The prefix was doing two jobs, disambiguating the UID and labelling the namespace, and as a dot joined
segment it read as a namespace that does not exist. Titles said `Namespace linq2db.Tools.LinqToDB.Tools`
while the types in it reported the real `LinqToDB.Tools`, and authored xrefs had to name the made up one.
Display names now keep the namespace as declared, and the new per entry `assemblyLabel` decides how the
assembly is shown: `suffix` appends it to the namespace label, `none` never does, `page` names it on the
namespace page the way type pages do, and `auto` picks `suffix` for a flattened layout and `none` for a
nested one, where a per assembly root node already names it.
Consumers that had to follow the separator:
- `SymbolUrlResolver.GetDocfxUrl` split the comment id on every `:`, so a qualified UID collapsed to its
assembly and every generated URL pointed at the same page.
- `XmlComment.ApplyAssemblyUid` joined crefs with a dot, which pointed them at UIDs no page has.
- `PathFriendlyId` maps `:` to `-`, one dash per character, matching `PathUtility.ToCleanUrlFileName`,
which names the member pages of `memberLayout: separatePages` in the build stage.
- `YamlMetadataResolver` groups a nested table of contents by assembly, in a node that carries no UID so
it needs no page, and no longer promotes a namespace out of it when it is the only one.
- `XrefInlineShortParser` accepts `::` so `@a::Ns.Type` does not end at the assembly.
Also fixes the global namespace: it is qualified like everything else, so two assemblies no longer share
the one page named by `globalNamespaceId`, and it finally has a display name instead of an empty table of
contents label (dotnet#9458).
Verified with the CSharp and SeedMarkdown snapshots, which are byte identical with the options unset.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dd95c86 to
9907932
Compare
Draft of a fix for dotnet/docfx#8966, opened against the fork for review before proposing it upstream. Generalizes the
custom/linq2dbglobalPrefixhack into a project-agnostic, tested option, and has been validated against the real linq2db docs build (see Validation below).Problem
A docfx UID is Roslyn's documentation comment id minus its
X:prefix (VisitorHelper.GetId), so it carries no assembly component. When one docfx project documents several assemblies that declare the same namespace, their APIs collapse onto one identity:MergeMemberskeys a flatDictionary<string, MetadataItem>by UID — namespaces and classes are silently merged, everything else is dropped with anIgnore duplicated memberwarning..ymlfile name is the UID, so pages overwrite each other and.manifestwarns.DocumentBuildContext.XRefSpecMapreportsDuplicateUidsand picks the winner alphabetically by href — which is why every link to a shared namespace lands in one project.This is common for platform/version specific packages that intentionally expose the same API surface (linq2db's per-EF-Core-version packages, Xamarin/WinForms/WPF variants,
Abstractions+ implementation pairs).Related: dotnet#9371, dotnet#2041, discussions dotnet#8204 and dotnet#8018.
Why not resolve hrefs at the metadata stage
On dotnet#8966 the suggestion was to "resolve the right project for the API pages by moving the resolve logic from build stage to metadata stage". That fixes hrefs only. It does not stop
MergeMembersfrom dropping or merging same-UID pages, so the affected APIs still never get a page. Disambiguating the UID itself is the only fix that addresses all four symptoms.Solution
A project level option plus a narrow per entry escape hatch, both off by default.
assemblyUidPrefixes— a top leveldocfx.jsonpropertyMaps an assembly name to a prefix that is prepended to the UID of every API declared in that assembly:
{ "assemblyUidPrefixes": { "MyLib": "Core", "MyLib.Ef8": "Ef8" }, "metadata": [ { "src": [ "src/MyLib/MyLib.csproj" ], "dest": "api/core" }, { "src": [ "src/MyLib.Ef8/MyLib.Ef8.csproj" ], "dest": "api/ef8" } ] }MyLib.WidgetbecomesCore.MyLib.WidgetandEf8.MyLib.Widget, so each keeps its own page, TOC entry and cross references. Assemblies that are not listed are untouched, so BCL/NuGet references, Microsoft Learn links and existing xref maps are unaffected.It sits next to
metadatarather than inside an entry because it has to be project wide. An entry mints UIDs not only for the APIs it documents but also for the APIs it references — theEf8entry emits reference UIDs for theMyLibtypes in its own signatures — and those must come out identical to the UIDs theMyLibentry produced. A per entry list cannot do that, because an entry cannot see another entry's settings.Measured on the linq2db docs build: replacing this with a per entry prefix on all 16 entries leaves 6690 cross-entry references across 163 pages pointing at UIDs no page has. They render as plain text with no link, no warning and no error — the total warning count is identical either way. The practical rule that follows is in the docs: list every assembly whose APIs appear in another assembly's public signatures, not just the ones whose namespaces collide.
uidPrefixOverride— per entry, for entries that build the same assembly nameVersion specific packages are often one project built several times, sharing an
AssemblyNameand differing only by target framework, which a map keyed by assembly name cannot separate:{ "assemblyUidPrefixes": { "MyLib": "Core" }, "metadata": [ { "src": [ "src/MyLib/MyLib.csproj" ], "dest": "api/core" }, { "src": [ "src/MyLib.Ef/MyLib.Ef.Ef8.csproj" ], "dest": "api/ef8", "uidPrefixOverride": "Ef8" }, { "src": [ "src/MyLib.Ef/MyLib.Ef.Ef9.csproj" ], "dest": "api/ef9", "uidPrefixOverride": "Ef9" } ] }It wins over
assemblyUidPrefixesfor its own entry's assemblies.What it fixes: the collision between the entries that declare it. Each gets its own pages, TOC entries and file names, and everything inside those pages — references,
<see cref="..."/>links, member anchors — is consistent with them.What it does not fix, both following from the fact that it names an entry rather than an assembly:
MyLib.Ef.dllcannot know whether you meantEf8orEf9, so those references lose their links silently. The fix needs no extra option: list the assembly inassemblyUidPrefixestoo, naming the version that should be the default link target. The override still wins for the assemblies its own entry documents, so both versions keep their pages while every other entry resolvesMyLib.Efreferences to the chosen one. The trade-off is that all such links go to that one version — a reference cannot resolve to "whichever version the referencing assembly was built against", because by the time the UID is minted the only thing distinguishing the versions is which entry documented them.srcglob matching the same assembly built for several target frameworks still collides and still reportsIgnore duplicated member. Narrowing the glob is the fix there, not a prefix.assemblyUidPrefixesassemblyUidPrefixesuidPrefixOverrideon eachassemblyUidPrefixes, naming the default targetsrcglobAlternative considered: one option, two-pass compile
uidPrefixOverridealone would be enough ifExeccompiled every entry first, collected assembly → prefix from each entry, and only then generated. Cross-entry references would resolve from that collected table andassemblyUidPrefixeswould not be needed.Not done here: it holds every Roslyn compilation in memory simultaneously (for linq2db, 17 projects across multiple target frameworks), and restructuring the compile pipeline is a much larger change than the bug warrants. Worth revisiting separately.
Implementation
The prefix is inserted in the private
VisitorHelper.GetDocumentationCommentId, next to the existingglobalNamespaceIdinsertion. That single hook covers uids, comment ids, overload ids, the references table, spec ids, TOC node ids and output file names. It is skipped for type parameters and for symbols with no containing assembly (cref-resolved symbols hit the latter).uidPrefixOverrideis applied inBuildright afterCompile, since an entry's assemblies are only known once compiled. It stays constant for the whole entry, so the parallel API page generation can read it safely.Three consumers do not go through that hook and needed to follow the prefix explicitly. Each of these is a bug the
globalPrefixhack still has, and each one shows up in the linq2db output below:SymbolUrlResolver.GetDocfxUrlbuilt hrefs from the raw Roslyn comment id while deriving file names throughVisitorHelper, so references and in-page anchors pointed at pages and bookmarks that do not exist.XmlCommentturnsT:Foo.Barinto a uid by pure text strip with no symbol context, so<see cref="..."/>would produce dangling xrefs. AResolveUidPrefixcallback onXmlCommentParserContextresolves the target through the compilation (DocumentationCommentId.GetFirstSymbolForDeclarationId, the same callAddReferencealready makes) and is supplied by both the mref and apiPage comment parsers. It is a no-op when neither option is set.VisitorHelper.GetRawId, sofilterConfiguidRegexrules keep matching the actual API surface and existing filter files keep working when the options are enabled.Namespace display names include the prefix, otherwise namespaces from different assemblies are indistinguishable in the TOC, breadcrumbs and page titles, and the parent-namespace trimming in
ToTocItemViewModel(which compares the display name against the parent uid) silently stops matching. WithnamespaceLayout: nestedthe prefix groups that assembly's namespaces under a single root node, which also answers discussion dotnet#8018.A prefix must start with a letter or underscore and may contain letters, digits, underscores and dots, e.g.
Core,MyLib.V2ornet8.0. Segments after the first may start with a digit, unlike a namespace, so target framework style prefixes work. The grammar is deliberately stricter thanglobalNamespaceId— which is inserted the same way and validates nothing at all — because the UID becomes a file name, an xref key and an HTML anchor, and path or UID metacharacters would corrupt all three. Invalid prefixes, empty assembly names and conflicting mappings are reported asInvalidUidPrefixwarnings and skipped.Behaviour when unset
Off by default and inert:
GetUidPrefixreturns immediately when neither option is configured, so there is no behaviour change and no measurable cost.Verified byte-exactly: the snapshot suite was run on a clean
maincheckout and on this branch, and all 497 generated files are SHA-256 identical. Re-verified after each subsequent commit. No.verified.*file is touched by this PR.Tests
test/Docfx.Dotnet.Tests/UidPrefixUnitTest.cs(new, 15 cases): namespace/type/member/overload uids and comment ids; two assemblies sharing a namespace getting distinct uids; cross-assembly references carrying the target's prefix; unmapped assemblies and framework types untouched; crefs, seealsos, exceptions andOverload:crefs, under both options; generics and type parameters prefixed exactly once; composition withglobalNamespaceId; filter rules matching unprefixed uids; the override separating assemblies that share an assembly name, winning over the map, and not leaking to other assemblies; and no prefix at all when neither option is set.test/docfx.Tests/MetadataCommandTest.cs(4 new end-to-end cases over two real projects sharing a namespace): theIgnore duplicated memberwarning and lost page without the options (locking in the regression), distinct pages/manifest entries/TOC entries with the map, the nested TOC grouping, and two entries separated by the override.schemas/docfx.schema.json(which isadditionalProperties: false).Docs
docs/reference/docfx-json-reference.md: a section per option, each stating when to reach for it and its trade-off.docs/docs/dotnet-api-docs.md: new "Assemblies that share namespaces" section with three subsections — how to give each assembly a prefix and why the map is project level; whatuidPrefixOverridedoes and does not fix; and "Nominate a default version for links from elsewhere", the setup for pointing other entries at one of several same-named assemblies, written as a procedure with a table of which prefix is used when generating each thing. Closes with a decision table and the caveat that enabling either option changes UIDs, so<xref>links in markdown, overwrite files and external xref maps need updating by hand.Validation against the linq2db docs build
Tested on
linq2db.docsbranchdocs/republish-uid-prefixes(linq2db/docs#64) — 17 metadata entries, 2389 generated API files.This is what surfaced the need for
uidPrefixOverride. linq2db ships four Entity Framework Core packages built from one shared props file:All four (
EF3,EF8,EF9,EF10) therefore produce the same assembly name and need four different prefixes. With only the map they collide on one key, trip the conflict warning, and EF9/EF10 keep colliding with EF8 exactly as before.Both builds were run from source at Roslyn 5.6.0 for an apples-to-apples comparison. All 2389 generated API file names are identical. The site build differs sharply:
globalPrefixhackInvalidBookmark(dead in-page anchors)Ignore duplicated memberInvalidAssemblyReferenceThe three consistency fixes account for the difference:
1. Malformed
commentId. The hack prepends the prefix to the whole documentation comment id, so it lands before the kind marker:2. Dead namespace/type hrefs, from the
GetDocfxUrlgap:3. 1197 dead in-page anchors. Same root cause — the hack generated member anchors unprefixed (
#LinqToDB_Internal_SchemaProvider_DataTypeInfo_CreateFormat) while the target pages contain the prefixed bookmark.The docs PR also fixes two article xrefs the hack was hiding. It rendered
<a class="xref" href="LinqToDB.ProviderName.html">with no warning, and that file does not exist in_site— they were already silently broken links on the published site. This build reports them asUidNotFoundinstead, and with the UIDs corrected both now resolve.Verification performed
dotnet build -c Release --warnAsErrorclean across net8.0/net9.0/net10.0.Docfx.Dotnet.Tests, 118docfx.Tests, 14Docfx.Build.ManagedReference.Testspass.mainbaseline (above).dotnet format --verify-no-changesreports nothing in any file touched here.DuplicateUids/UidNotFoundwarnings and a dropped page; with them, 0 warnings, bothA.Shared.Widget.htmlandB.Shared.Widget.htmlgenerated, and each xref resolving to its own project.Not included
globalNamespaceIdinconsistency inGetDocfxUrlis left as is, to keep the "no change when unset" guarantee exact.IPropertySymbol.ReduceExtensionMember/IMethodSymbol.ReduceExtensionMembertoSymbolFormatter.Symbols.cs). Unrelated to this fix and would churn snapshots; dependabot Bump the roslyn group with 8 updates dotnet/docfx#11053 covers the upgrade separately. The linq2db build usescustom/linq2db-uidprefix, which is this branch plus that one commit.AssemblyNameListwhenMergeMembersmerges a namespace or class page. It is a real gap —samples/seed's ownCatLibrary.Corenamespace page reports onlyCatLibraryalthough half its types come fromCatLibrary.Core— but it changes default output, would require a snapshot update, and both shipped templates render onlyassemblies.0so nothing would become visible without a template change too. Belongs in its own PR.Review notes
uidPrefixOverridewas added).assemblyUidPrefixessays what its key is,uidPrefixOverridenames its relationship to it rather than being its singular.uidPrefixOverridedoes and does not fix.Fixes dotnet#8966, dotnet#9371.
🤖 Generated with Claude Code