Skip to content

Trim the documentation file with the assembly - #5

Merged
SimonCropp merged 2 commits into
mainfrom
trim-documentation
Oct 8, 2026
Merged

SimonCropp merged 2 commits into
mainfrom
trim-documentation

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Where a project writes an XML documentation file, the entries for the types and members the linker removed are now taken out of it. On by default; Squash_TrimDocumentation set to false leaves the file alone.

A source-only package compiled into a library documents its own members into that file, so the file can end up larger than the assembly beside it. Run over copies of Verify's build output:

File Before After Entries removed
Verify.xml net48 817,147 255,533 1,864
Verify.xml net10.0 317,104 228,185 308
Verify.NUnit.xml net48 595,681 17,933 1,919
Verify.NUnit.xml net10.0 100,574 11,059 310

How

  • A fifth linker step, RemovedDocumentation, runs after the output is written. It lists the documentation names of everything in the assembly under in/ that is not in the one under out/, reading both with System.Reflection.Metadata.
  • The task removes the entries with those names and nothing else. A name spelled differently from the compiler's leaves its entry in place, so a mistake in the spelling cannot remove the entry of a member that is still there.
  • What stays is never parsed and written again. The task only leaves bytes out, so the remaining entries are as the compiler wrote them, in the same order.

For a user

  • Squash_TrimDocumentation, default true.
  • Squash012, a warning when the file is not XML the task can follow. The assembly is trimmed all the same and the file is left as it was.
  • Each build writes removed-documentation.txt beside removed.txt, and keeps the compiler's file in the in folder.

Tests

  • A new Documented fixture with a member of every shape a documentation name can take. Each summary says Kept. or Removed., and the trimmed file is held to that on all three frameworks.
  • The trimmed file is compared with a second, independent way of cutting the same entries out of the compiler's file.
  • Integration tests build a real project: the file in bin and in the packed nupkg is trimmed, a repeat build leaves it alone, and turning the setting off compiles again and leaves the compiler's file.

Not covered

  • Not run against the .NET 11 linker. The step is placed with +OutputStep:, so it depends on the linker having a step of that name; the canary workflow will show whether it does.
  • The version is still 2.0.0.

Where a project writes an XML documentation file, the entries for the
types and members the linker removed are taken out of it. A source-only
package compiled into a library documents its own members into that
file: Verify.xml for net48 is 817 KB, of which 256 KB is left, and
Verify.NUnit.xml goes from 596 KB to 18 KB.

A new linker step, RemovedDocumentation, runs after the output is
written and lists the documentation names of everything in the input
assembly that is not in the output, reading both files with
System.Reflection.Metadata. The task removes the entries with those
names and nothing else, so a name spelled differently from the
compiler's leaves its entry in place and cannot remove the entry of a
member that is still there. What stays is never parsed and written
again: the task only leaves bytes out.

Squash_TrimDocumentation set to false leaves the file alone. Squash012
warns when the file is not XML the task can follow; the assembly is
trimmed all the same. Each build writes removed-documentation.txt and
keeps the compiler's file in the in folder.

The Documented fixture has a member of every shape a documentation name
can take, each with a summary that says whether the trim is expected to
keep it.
@SimonCropp SimonCropp added this to the 2.1.0 milestone Oct 8, 2026
CI builds the solution, and a project referenced from outside it is built in its default configuration: the fixture came out as Debug, where the tests look for Release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant