ReferenceTrimmer 3.1.23
See the version list below for details.
dotnet add package ReferenceTrimmer --version 3.1.23
NuGet\Install-Package ReferenceTrimmer -Version 3.1.23
<PackageReference Include="ReferenceTrimmer" Version="3.1.23"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ReferenceTrimmer" Version="3.1.23" />
<PackageReference Include="ReferenceTrimmer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ReferenceTrimmer --version 3.1.23
#r "nuget: ReferenceTrimmer, 3.1.23"
#:package ReferenceTrimmer@3.1.23
#addin nuget:?package=ReferenceTrimmer&version=3.1.23
#tool nuget:?package=ReferenceTrimmer&version=3.1.23
ReferenceTrimmer
Easily identify which dependencies can be removed from an MSBuild project.
How to use
Add a package reference to the ReferenceTrimmer package in your projects. The package contains build logic to emit warnings when unused dependencies are detected.
If you're using Central Package Management, you can it as a GlobalPackageReference in your Directory.Packages.props to apply it to the entire repo.
<ItemGroup>
<GlobalPackageReference Include="ReferenceTrimmer" Version="{SomeVersion}" />
</ItemGroup>
Alternately, you can add a PackageReference to your Directory.Build.props or Directory.Build.targets to apply to the entire repo.
You'll need to enable C# documentation XML generation to ensure good analysis results. If your repo is not already using docxml globally, this can introduce a large number of errors and warnings specific to docxml. Additionally, turning on docxml adds additional output I/O that can slow down large repos. You can turn off specific docxml related warnings and errors while defaulting ReferenceTrimmer to off using a block of code like this in your Directory.Build.props. Turn on the ReferenceTrimmer build by setting /p:EnableReferenceTrimmer=true on the MSBuild command line or setting the same property value as an environment variable. You could create a separate build pipeline for your repo to run ReferenceTrimmer builds.
<PropertyGroup Label="ReferenceTrimmer">
<EnableReferenceTrimmer Condition=" '$(EnableReferenceTrimmer)' == '' ">false</EnableReferenceTrimmer>
</PropertyGroup>
<PropertyGroup Condition=" '$(EnableReferenceTrimmer)' == 'true' and '$(GenerateDocumentationFile)' != 'true' " Label="ReferenceTrimmer">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);419;1570;1573;1574;1584;1591;SA1602</NoWarn>
</PropertyGroup>
Note: To get better results, enable the IDE0005 unnecessary using rule. This avoids the C# compiler seeing a false positive assembly usage from unneeded using directives causing it to miss a removable dependency. See also the note for why IDE0005 code analysis rule requires <GenerateDocumentationFile> property to be enabled. Documentation generation is also required for accuracy of used references detection (based on https://github.com/dotnet/roslyn/issues/66188).
Configuration
$(EnableReferenceTrimmer) - Controls whether the build logic should run for a given project. Defaults to true.
Rules
| Id | Description |
|---|---|
| RT0000 | Enable documentation generation for accuracy of used references detection |
| RT0001 | Unnecessary reference |
| RT0002 | Unnecessary project reference |
| RT0003 | Unnecessary package reference |
How does it work?
There are two main pieces to the package. First there is an MSBuild task which collects all refernces passed to the compiler. There is also a Roslyn Analyzer which uses the GetUsedAssemblyReferences analyzer API which is available starting with Roslyn compiler that shipped with Visual Studio 2019 version 16.10, .NET 5. (see https://github.com/dotnet/roslyn/blob/main/docs/wiki/NuGet-packages.md#versioning). This is the compiler telling us exactly what references were needed as part of compilation. The analyzer then compares the set of references the Task gathered with the references the compiler says were used.
Future development
The outcome of https://github.com/dotnet/sdk/issues/10414 may be of use for ReferenceTrimmer future updates.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on ReferenceTrimmer:
| Repository | Stars |
|---|---|
|
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.3.12 | 371,205 | 7/2/2025 |
| 3.3.11 | 659,792 | 2/25/2025 |
| 3.3.10 | 613,005 | 10/1/2024 |
| 3.3.6 | 129,177 | 4/1/2024 |
| 3.3.3 | 3,149 | 3/27/2024 |
| 3.3.2 | 554 | 3/23/2024 |
| 3.3.1 | 1,884 | 3/8/2024 |
| 3.3.0 | 305 | 3/6/2024 |
| 3.2.4 | 15,255 | 2/2/2024 |
| 3.2.3 | 809 | 11/1/2023 |
| 3.2.0 | 954 | 10/2/2023 |
| 3.1.26 | 555 | 9/19/2023 |
| 3.1.23 | 334 | 9/15/2023 |
| 3.1.22 | 501 | 9/9/2023 |
| 3.1.17 | 2,026 | 6/7/2023 |
| 3.1.16 | 529 | 3/8/2023 |
| 3.1.15 | 458 | 2/24/2023 |
| 3.1.12 | 685 | 2/3/2023 |
| 3.1.11 | 1,043 | 1/28/2023 |
| 3.1.10 | 508 | 1/25/2023 |
| 3.1.8 | 520 | 1/21/2023 |
| 3.1.7 | 419 | 1/19/2023 |
| 3.1.5 | 481 | 1/18/2023 |
| 3.1.4 | 483 | 1/17/2023 |
| 3.1.2 | 476 | 1/12/2023 |
| 3.1.0 | 488 | 1/5/2023 |
| 3.0.8 | 603 | 10/11/2022 |
| 3.0.7 | 545 | 10/11/2022 |
| 3.0.5 | 577 | 9/9/2022 |
| 3.0.4-g961fd51237 | 333 | 9/9/2022 |
| 2.0.0 | 3,829 | 10/5/2018 |