### Combined Configuration Example
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Example showing both adding custom packages and removing default packages in a single ItemGroup.
```xml
```
--------------------------------
### Instantiate DeclaredReference examples
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/types.md
Examples showing how to create instances for different reference types.
```csharp
// Bare reference
var declaredRef = new DeclaredReference(
"C:\\Program Files\\dotnet\\...\\System.Data.dll",
DeclaredReferenceKind.Reference,
"System.Data",
string.Empty);
// Project reference
var projRef = new DeclaredReference(
"C:\\repos\\MyApp\\bin\\Debug\\OtherLib.dll",
DeclaredReferenceKind.ProjectReference,
"../OtherLib/OtherLib.csproj",
"OtherLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
// Package reference
var pkgRef = new DeclaredReference(
"C:\\Users\\user\\.nuget\\packages\\json\\13.0.3\\lib\\net45\\Newtonsoft.Json.dll",
DeclaredReferenceKind.PackageReference,
"Newtonsoft.Json",
string.Empty);
```
--------------------------------
### Implement Initialize method
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Example implementation of the Initialize method to hook into MSBuild events.
```csharp
// Called automatically by MSBuild when the logger is loaded
// No explicit usage in application code
public void Initialize(IEventSource eventSource)
{
_eventSource = eventSource;
eventSource.TaskStarted += OnTaskStarted;
eventSource.TaskFinished += OnTaskFinished;
eventSource.MessageRaised += OnMessageRaised;
}
```
--------------------------------
### ProjectPath Property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Gets or sets the full path to the .vcxproj file.
```csharp
public string ProjectPath { get; set; }
```
--------------------------------
### Example Linker Output for Unused Libraries
Source: https://github.com/dfederm/referencetrimmer/blob/main/README.md
This is an example of the linker output when using MSVC link.exe flags /VERBOSE:UNUSEDLIBS and /VERBOSE:UNUSEDDELAYLOAD, which indicate unused .lib files and delay-load DLLs.
```text
Unused libraries:
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64\gdi32.lib
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64\winspool.lib
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64\comdlg32.lib
```
--------------------------------
### RT0003 Diagnostic Example
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Demonstrates a project file entry that triggers the RT0003 diagnostic and the resulting output.
```xml
```
```csharp
// No types from Unused.Json are used
```
```text
RT0003: PackageReference Unused.Json can be removed
```
--------------------------------
### Example Linker Output
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Sample output format from the MSVC linker that the logger parses to identify unused libraries.
```text
Unused libraries:
C:\Windows\System32\kernel32.lib
C:\packages\mylib\lib\unused.lib
(empty line signals end)
```
--------------------------------
### RT0002 Project Reference Example
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Demonstrates an unused project reference that triggers the RT0002 diagnostic.
```xml
```
```csharp
// No types or members from Dependency are used
```
```text
RT0002: ProjectReference ..\Dependency\Dependency.csproj can be removed
```
--------------------------------
### RT0001 Bare Reference Example
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Demonstrates a bare reference that is not used in the code, triggering the RT0001 diagnostic.
```xml
```
```csharp
using System.IO; // IO is used
using Unused.Logging; // Logging is NOT used
```
```text
RT0001: Reference Unused.Logging can be removed
```
--------------------------------
### Install ReferenceTrimmer NuGet Package
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/README.md
Add this PackageReference to your project file to include ReferenceTrimmer in your build process.
```xml
```
--------------------------------
### Reference Trimmer Log File Format
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
Example content for the diagnostic log files generated when EnableReferenceTrimmerDiagnostics is enabled.
```text
C:\path\to\System.Runtime.dll
C:\path\to\MyLibrary.dll
```
--------------------------------
### Example Unused Library Output
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Human-readable text output generated when the Link task detects unused MSVC libraries.
```text
Unused MSVC libraries detected in project C:\projects\MyApp\MyApp.vcxproj:
* Default Windows SDK import libraries:
- Libraries needed: advapi32.lib;shell32.lib (set in $(AdditionalDependencies) without %(AdditionalDependencies))
- Unneeded: gdi32.lib, winspool.lib (remove from $(AdditionalDependencies))
* Other libraries - if a lib from a project in this repo, remove the related ProjectReference
to improve your build dependency graph; if a package lib, remove from $(AdditionalDependencies):
- C:\packages\unused\lib\unused.lib
```
--------------------------------
### UnusedLibraryPathsJson Property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Gets or sets the JSON-formatted string of classified unused libraries.
```csharp
public string UnusedLibraryPathsJson { get; set; }
```
--------------------------------
### NuGetPackageRoot Property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Sets the root directory for installed NuGet packages to identify and skip injected references.
```csharp
public string? NuGetPackageRoot { get; set; }
```
--------------------------------
### Report RT9999 diagnostic error
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
Example of the diagnostic output format when an unhandled exception occurs during analysis.
```text
RT9999: ReferenceTrimmer encountered an unexpected error: Object reference not set to an instance of an object.
Please file a bug at https://github.com/dfederm/ReferenceTrimmer/issues
```
--------------------------------
### Declared References TSV Format
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
The schema definition and example content for the tab-separated values file used for declared references.
```text
AssemblyPath\tKind\tSpec[\tProjectAssemblyIdentity]
```
```text
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.0\System.Runtime.dll Reference System.Runtime
C:\repos\MyApp\bin\Debug\Helper.dll ProjectReference ../Helper/Helper.csproj Helper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
C:\Users\user\.nuget\packages\json\13.0.0\lib\net45\Newtonsoft.Json.dll PackageReference Newtonsoft.Json
```
--------------------------------
### Opt-In Configuration
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Set default behavior in Directory.Build.props and enable the tool for specific projects.
```xml
false
```
```xml
true
```
--------------------------------
### Configure Documentation and Warnings
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Enable documentation file generation and suppress common documentation-related warnings.
```xml
true$(NoWarn);CS1591;SA1600;SA1601
```
--------------------------------
### Initialize Method
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Initializes the logger and sets up event handling for worker node events.
```csharp
public override void Initialize(IEventSource eventSource)
```
--------------------------------
### Enable Experimental Symbol-Based Analysis
Source: https://github.com/dfederm/referencetrimmer/blob/main/README.md
Opt into the experimental symbol-based analysis mode by setting this property in your Directory.Build.props. This mode does not require documentation file generation and offers more precise detection for ProjectReference and PackageReference.
```xml
true
```
--------------------------------
### Enable Documentation Generation in Project File
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Configuration to enable XML documentation generation in MSBuild project files.
```xml
true
```
```xml
true$(NoWarn);1591;SA1600;SA1601
```
--------------------------------
### Enable C# Documentation File Generation
Source: https://github.com/dfederm/referencetrimmer/blob/main/README.md
Enable documentation file generation in Directory.Build.props for accurate C# reference analysis and suppress related warnings. This is required for the default analysis mode.
```xml
true$(NoWarn);419;1570;1573;1574;1584;1591;SA1602
```
--------------------------------
### Initialize DeclaredReference
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/types.md
Constructor signature for creating a new instance.
```csharp
DeclaredReference(
string assemblyPath,
DeclaredReferenceKind kind,
string spec,
string projectAssemblyIdentity);
```
--------------------------------
### Define ReferenceTrimmerIgnorePackageBuildFiles Item
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Basic syntax for adding a package to the ignore list.
```xml
```
--------------------------------
### Enable GenerateDocumentationFile in MSBuild
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Configures the C# compiler to generate XML documentation files, which is required for accurate ReferenceTrimmer analysis.
```xml
true
```
--------------------------------
### Analyzer initialization usage note
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
Note regarding the automatic nature of analyzer initialization.
```csharp
// Analyzer initialization is automatic when included in a project
// via the NuGet package. Roslyn calls Initialize() internally.
// No explicit usage required in user code.
```
--------------------------------
### Execute
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
The main entry point for the MSBuild task that collects references, applies filtering rules, and writes the output to a TSV file.
```APIDOC
## Execute
### Description
Main entry point called by MSBuild. Collects all declared references, applies filtering rules, and writes them to `OutputFile` in TSV format.
### Method
public override bool Execute()
### Returns
- **bool** - true if execution succeeded; false if errors were logged
```
--------------------------------
### ReferenceTrimmer Help Keyword Constant
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Public constant used for event classification, log file naming, and IDE help link generation.
```csharp
public const string HelpKeyword = "ReferenceTrimmerUnusedMSVCLibraries";
```
--------------------------------
### Execute Method
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
The primary entry point for the MSBuild task that performs reference collection and filtering.
```csharp
public override bool Execute()
```
--------------------------------
### Initialize ForwardingLogger overloads
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Overloaded methods to register event handlers with the MSBuild event source.
```csharp
public void Initialize(IEventSource eventSource, int nodeCount)
public void Initialize(IEventSource eventSource)
```
--------------------------------
### Module Dependency Graph
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
Visual representation of the ReferenceTrimmer package structure and its internal dependencies.
```text
┌───────────────────────────────┐
│ ReferenceTrimmer (Package) │
├───────────────────────────────┤
│ │
├─→ ReferenceTrimmer.Tasks │
│ └─ CollectDeclaredReferencesTask
│ └─ Shared/DeclaredReferences
│ └─ NuGet.ProjectModel
│
├─→ ReferenceTrimmer.Analyzer │
│ └─ ReferenceTrimmerAnalyzer
│ └─ Shared/DeclaredReferences
│ └─ Roslyn APIs
│
├─→ ReferenceTrimmer.Loggers │
│ ├─ CentralLogger
│ ├─ ForwardingLogger
│ └─ UnusedLibsCustomBuildEventArgs
│
├─→ ReferenceTrimmer.props │
│ └─ Defines properties
│ └─ Loads tasks assembly
│ └─ Sets MSVC linker flags
│
└─→ ReferenceTrimmer.targets │
└─ Defines build targets
└─ Orchestrates pipeline
```
--------------------------------
### Define ProjectAssetsFile property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for the path to the project.assets.json file.
```csharp
public string? ProjectAssetsFile { get; set; }
```
--------------------------------
### Project File Organization
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/README.md
The directory structure of the ReferenceTrimmer documentation.
```text
output/
├── README.md ← You are here
├── architecture-overview.md ← System design and integration
│
├── api-reference-analyzer.md ← Roslyn analyzer API
├── api-reference-task.md ← MSBuild task API
├── api-reference-loggers.md ← MSVC logger APIs
│
├── types.md ← Type definitions and contracts
├── configuration.md ← MSBuild properties and items
└── errors.md ← Diagnostics and error handling
```
--------------------------------
### Configure Symbol-Based Analysis
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Switches the analysis engine to an experimental symbol-based detection method. This mode does not require documentation files and handles transitive references more precisely.
```xml
false
```
```xml
true
```
```csharp
// With default analysis, this assembly might be missed
// if only used in transitive reference
using TransitiveUsage;
var obj = new TransitiveClass();
```
--------------------------------
### Enable Diagnostic Logging
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Enable diagnostic logging to generate reference analysis files in the intermediate output path.
```xml
truetrue
```
--------------------------------
### GetPackageInfos Method
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Resolves PackageReferences by loading the NuGet lock file and mapping packages to their assemblies.
```csharp
private Dictionary GetPackageInfos()
```
```csharp
Dictionary contains:
"Newtonsoft.Json" → CompileTimeAssemblies: { /path/to/Newtonsoft.Json.dll }
"Microsoft.Extensions.Logging.Abstractions" → CompileTimeAssemblies: { ... }
```
--------------------------------
### Default Ignored Packages List
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
The list of packages included by default that have inconsequential build files.
```text
Microsoft.Extensions.Caching.Abstractions
Microsoft.Extensions.Caching.Memory
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Abstractions
Microsoft.Extensions.Configuration.Binder
Microsoft.Extensions.Configuration.CommandLine
Microsoft.Extensions.Configuration.EnvironmentVariables
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.Configuration.UserSecrets
Microsoft.Extensions.DependencyInjection
Microsoft.Extensions.DependencyInjection.Abstractions
Microsoft.Extensions.DependencyModel
Microsoft.Extensions.Diagnostics
Microsoft.Extensions.Diagnostics.Abstractions
Microsoft.Extensions.FileProviders.Abstractions
Microsoft.Extensions.FileProviders.Composite
Microsoft.Extensions.FileProviders.Physical
Microsoft.Extensions.FileSystemGlobbing
Microsoft.Extensions.Hosting
Microsoft.Extensions.Hosting.Abstractions
Microsoft.Extensions.Http
Microsoft.Extensions.Logging
Microsoft.Extensions.Logging.Abstractions
Microsoft.Extensions.Logging.Configuration
Microsoft.Extensions.Logging.Console
Microsoft.Extensions.Logging.Debug
Microsoft.Extensions.Logging.EventLog
Microsoft.Extensions.Logging.EventSource
Microsoft.Extensions.Options
Microsoft.Extensions.Options.ConfigurationExtensions
Microsoft.Extensions.Primitives
System.Text.Json
System.ValueTuple
```
--------------------------------
### Initialize analyzer method signature
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
Registers the analyzer with the Roslyn compilation context.
```csharp
public override void Initialize(AnalysisContext context)
```
--------------------------------
### Override Property Resolution
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Demonstrates how a project file overrides a property defined in Directory.Build.props.
```xml
false
```
```xml
true
```
--------------------------------
### Configure OutputFile property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Required property for specifying the destination path of the generated TSV file.
```csharp
[Required]
public string? OutputFile { get; set; }
```
--------------------------------
### Implement Custom Logger
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
Re-implement the IForwardingLogger interface to create a custom logger for MSBuild.
```csharp
public class CustomLogger : IForwardingLogger { }
```
--------------------------------
### Roslyn Analyzer Lifecycle Sequence
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
The step-by-step execution flow of the Roslyn analyzer from discovery to diagnostic reporting.
```text
1. Roslyn discovers analyzer via assembly attribute
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
2. Roslyn calls Initialize(AnalysisContext)
→ RegisterCompilationStartAction()
3. At compilation start:
→ Find _ReferenceTrimmer_DeclaredReferences.tsv in additional files
→ If found, continue; if not, abort (ReferenceTrimmer disabled)
→ Read configuration (ReferenceTrimmerUseSymbolAnalysis)
→ Route to default or symbol-based analysis
4. During compilation:
→ Default: Wait for compilation end, call GetUsedAssemblyReferences()
→ Symbol-based: Register symbol and operation callbacks
5. At compilation end:
→ Compare declared vs. used references
→ Report diagnostics (RT0001, RT0002, RT0003)
6. Roslyn reports diagnostics to IDE/build output
```
--------------------------------
### Constructor for UnusedLibsCustomBuildEventArgs
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Initializes a new instance of the event arguments with project and library details.
```csharp
public UnusedLibsCustomBuildEventArgs(
string message,
string projectPath,
string unusedLibraryPathsJson)
: base(message, ForwardingLogger.HelpKeyword, senderName: projectPath)
```
--------------------------------
### Enable ReferenceTrimmer Diagnostics
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Enables the generation of log files containing used and unused references in the intermediate output directory.
```xml
false
```
```text
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.0\System.Runtime.dll
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.0\System.Collections.dll
C:\projects\myapp\bin\Debug\MyLibrary.dll
```
```xml
true
```
--------------------------------
### Add Additional Packages to Ignore List
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Syntax to include a custom package in the ignore list for trimming.
```xml
```
--------------------------------
### Configure Linker Flags in ReferenceTrimmer.props
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Automatically injects verbose linker flags into the MSBuild project when the ReferenceTrimmer is enabled.
```xml
/VERBOSE:UNUSEDLIBS /VERBOSE:UNUSEDDELAYLOAD %(AdditionalOptions)
```
--------------------------------
### Define ReferenceInfo helper class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
Internal class used to track assembly symbols and file paths, supporting multiple assemblies or paths per identity.
```csharp
private sealed class ReferenceInfo(IAssemblySymbol assembly)
{
public IAssemblySymbol Assembly { get; }
public List? AdditionalAssemblies { get; }
public string? Path { get; }
public List? AdditionalPaths { get; }
public void AddAssembly(IAssemblySymbol assembly);
public void AddPath(string path);
}
```
--------------------------------
### Define ProjectReferences property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for project-to-project references.
```csharp
public ITaskItem[]? ProjectReferences { get; set; }
```
--------------------------------
### Define References property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for bare assembly references.
```csharp
public ITaskItem[]? References { get; set; }
```
```csharp
// Represents
// or
```
--------------------------------
### Handling Reflection-Based Usage
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Use this pattern when an assembly is loaded via reflection and not detected by the analyzer.
```csharp
// Assembly is used via reflection but not detected
var type = Type.GetType("Unused.Types.MyClass", throwOnError: false);
```
--------------------------------
### GetTargetFrameworkAssemblyNames Method
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Scans framework directories to identify assemblies that cannot be removed.
```csharp
private HashSet GetTargetFrameworkAssemblyNames()
```
```text
System.Runtime
System.Collections
System.Data
System.Net.Http
```
--------------------------------
### GlobalPackageReference for ReferenceTrimmer
Source: https://github.com/dfederm/referencetrimmer/blob/main/README.md
Add this to your Directory.Packages.props file for Central Package Management to apply ReferenceTrimmer to the entire repository.
```xml
```
--------------------------------
### TargetFrameworkDirectories Property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Defines an array of directories to scan for framework assemblies that should be excluded from trimming.
```csharp
public ITaskItem[]? TargetFrameworkDirectories { get; set; }
```
--------------------------------
### Default Constructor
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Parameterless constructor required for deserialization.
```csharp
public UnusedLibsCustomBuildEventArgs()
```
--------------------------------
### Ignore Custom Package Build Files
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Exclude specific packages from build file analysis.
```xml
```
--------------------------------
### Shutdown Method
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Finalizes the JSON log file and cleans up resources.
```csharp
public override void Shutdown()
```
--------------------------------
### Implement SupportedDiagnostics property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
Returns the immutable array of all supported diagnostic descriptors.
```csharp
public override ImmutableArray SupportedDiagnostics
=> ImmutableArray.Create(
RT0000Descriptor,
RT0001Descriptor,
RT0002Descriptor,
RT0003Descriptor,
RT9999Descriptor);
```
--------------------------------
### Define PackageInfoBuilder Internal Class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Builder pattern implementation for accumulating package dependency data.
```csharp
private sealed class PackageInfoBuilder
{
public void AddCompileTimeAssemblies(List compileTimeAssemblies);
public void AddBuildFiles(List buildFiles);
public PackageInfo ToPackageInfo();
}
```
--------------------------------
### C++ Analysis Event-Based Communication
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
Diagram illustrating the event forwarding process between worker and main nodes for C++ library analysis.
```text
ForwardingLogger (on worker node)
↓
parses linker output
↓
creates UnusedLibsCustomBuildEventArgs
↓
forwards via BuildEventRedirector
↓
CentralLogger (on main node)
↓
aggregates events
↓
writes JSON log file
↓
ReferenceTrimmerUnusedMSVCLibraries.json.log
```
--------------------------------
### Define PackageInfo Internal Record
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Immutable storage for package compile-time assemblies and build files.
```csharp
private readonly record struct PackageInfo(
IReadOnlyCollection CompileTimeAssemblies,
IReadOnlyCollection BuildFiles);
```
--------------------------------
### Remove Package from Default Ignore List
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Syntax to remove a package from the default ignore list to enable trimming evaluation.
```xml
```
--------------------------------
### Distributed Logger Parameter Format
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
The required syntax for the -distributedlogger command line argument.
```text
-distributedlogger:, * ,
```
--------------------------------
### Handling Transitive Dependencies
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Use this pattern when a direct reference is removed but its transitive dependency remains required.
```xml
```
--------------------------------
### Access AssemblyPath field
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/types.md
Represents the absolute file system path to the resolved assembly.
```csharp
string AssemblyPath { get; }
```
--------------------------------
### Define IgnorePackageBuildFiles property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for overriding build file exclusion for specific packages.
```csharp
public ITaskItem[]? IgnorePackageBuildFiles { get; set; }
```
```csharp
//
```
--------------------------------
### RT0002 Resolution Options
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Provides methods to remove, replace, or suppress an unused project reference.
```xml
```
```xml
```
```xml
```
--------------------------------
### Enable Symbol-Based Analysis
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Enable the use of symbol-based analysis for reference trimming.
```xml
true
```
--------------------------------
### Symbol-Based Analysis Callbacks
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
The registration flow for symbol, operation, and syntax node actions when symbol-based analysis is enabled.
```text
RegisterSymbolAction()
↓
Called for every NamedType, Method, Property, Field, Event
↓
Track return types, parameter types, constraints, attributes
RegisterOperationAction()
↓
Called for every operation (invocation, member reference, etc.)
↓
Track target method/member assembly, overloads, patterns
RegisterSyntaxNodeAction()
↓
Called for nameof() and references
↓
Track member/type references in syntax
```
--------------------------------
### RuntimeIdentifier Property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Sets the RID used to select runtime-specific libraries from the lock file.
```csharp
public string? RuntimeIdentifier { get; set; }
```
--------------------------------
### Handling Dynamic Code Generation
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Use the TreatAsUsed attribute for NuGet packages that generate code at build time without direct compile-time references.
```xml
```
--------------------------------
### Define PackageReferences property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for NuGet package references.
```csharp
public ITaskItem[]? PackageReferences { get; set; }
```
--------------------------------
### Ignore Package Build Files with ReferenceTrimmer
Source: https://github.com/dfederm/referencetrimmer/blob/main/README.md
Add a package to the ReferenceTrimmerIgnorePackageBuildFiles item in your project file or Directory.Build.props to prevent ReferenceTrimmer from evaluating its build files.
```xml
```
--------------------------------
### Access ProjectAssemblyIdentity field
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/types.md
The strong name of the assembly for ProjectReferences, otherwise empty.
```csharp
string ProjectAssemblyIdentity { get; }
```
--------------------------------
### Configure directory-level suppression
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Disable ReferenceTrimmer at the repository root using Directory.Build.props, then selectively re-enable it in specific projects.
```xml
false
```
```xml
true
```
--------------------------------
### Define TargetPlatformMoniker property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for the platform-specific moniker.
```csharp
public string? TargetPlatformMoniker { get; set; }
```
--------------------------------
### LocalEventRedirector Class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Internal adapter class for bridging local event forwarding.
```csharp
private sealed class LocalEventRedirector : IEventRedirector
{
private readonly Action _forwardEvent;
public void ForwardEvent(BuildEventArgs buildEvent);
}
```
--------------------------------
### Define _PrepareCollectDeclaredReferences Target
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Defines the target responsible for preparing paths and cache files before reference collection.
```xml
```
--------------------------------
### Define ResolvedReferences property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for resolved assembly paths.
```csharp
public ITaskItem[]? ResolvedReferences { get; set; }
```
--------------------------------
### Enable or Disable ReferenceTrimmer
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Controls the activation of the ReferenceTrimmer analysis pipeline. Set to false to disable or use conditional logic for opt-in behavior.
```xml
true
```
```xml
false
```
```xml
false
```
--------------------------------
### MSBuild Build Target Sequence
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
The sequence of MSBuild targets used to collect declared references and prepare them for the Roslyn analyzer.
```text
1. _PrepareCollectDeclaredReferences
├─ Depends on: ResolveAssemblyReferences, PrepareProjectReferences
├─ Prepares: Paths, properties, cache files
└─ Output: Properties set up for task
2. CollectDeclaredReferences
├─ Inputs: Reference items, project assets file, framework list
├─ Task: CollectDeclaredReferencesTask
└─ Output: _ReferenceTrimmer_DeclaredReferences.raw.tsv
3. _StabilizeCollectDeclaredReferences
├─ Input: .raw.tsv file
├─ Copies with WriteOnlyWhenDifferent
└─ Output: _ReferenceTrimmer_DeclaredReferences.tsv
4. CoreCompile
├─ Input: .tsv file (added to AdditionalFiles)
├─ Analyzer loaded by Roslyn
├─ Analyzer loads .tsv file
└─ Output: Diagnostics
```
--------------------------------
### Define ForwardingLogger properties
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Properties for configuring the logger, managing event redirection, and identifying the worker node.
```csharp
public LoggerVerbosity Verbosity { get; set; }
```
```csharp
public string? Parameters { get; set; }
```
```csharp
public IEventRedirector? BuildEventRedirector { get; set; }
```
```csharp
public int NodeId { get; set; }
```
--------------------------------
### JSON Log File Format
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
The structure of the generated JSON log file containing unused library information.
```json
[
{
"C:\\projects\\MyApp\\MyApp.vcxproj": [
{
"LibPath": "C:\\\\Windows\\\\System32\\\\gdi32.lib",
"LibType": "DefaultImportLib"
},
{
"LibPath": "C:\\\\packages\\\\unused\\\\lib\\\\unused.lib",
"LibType": "PackageOrDependencyLib"
}
]
}
]
```
--------------------------------
### Define UnusedLibsCustomBuildEventArgs class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
The class definition for the custom MSBuild event arguments.
```csharp
[Serializable]
internal sealed class UnusedLibsCustomBuildEventArgs : CustomBuildEventArgs
```
--------------------------------
### Suppress Reference for Reflection
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Mark a package as used to prevent it from being trimmed when accessed via reflection.
```xml
true
```
--------------------------------
### Access Kind field
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/types.md
Indicates the reference type via the DeclaredReferenceKind enumeration.
```csharp
DeclaredReferenceKind Kind { get; }
```
--------------------------------
### C# Analysis Data Flow
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
Diagram showing the communication path between the task and the analyzer via a TSV file.
```text
CollectDeclaredReferencesTask
↓
writes
↓
_ReferenceTrimmer_DeclaredReferences.tsv
↓
read by
↓
ReferenceTrimmerAnalyzer
```
--------------------------------
### Resolving RT0003: Remove, Suppress, or Mark as Used
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Provides options to resolve the diagnostic by removing the reference, suppressing the warning, or explicitly marking the package as used.
```xml
```
```xml
```
```xml
```
--------------------------------
### Define TargetFrameworkMoniker property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Property for the NuGet target framework moniker.
```csharp
public string? TargetFrameworkMoniker { get; set; }
```
--------------------------------
### Access Spec field
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/types.md
The user-visible identifier of the reference as declared in the project file.
```csharp
string Spec { get; }
```
--------------------------------
### Define CollectDeclaredReferencesTask class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
The base class definition for the MSBuild task.
```csharp
public sealed class CollectDeclaredReferencesTask : MSBuildTask
```
--------------------------------
### MSBuild Property Flow
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/architecture-overview.md
The flow of user-defined properties through the MSBuild targets to the final diagnostic output.
```text
User-defined properties (Directory.Build.props, project file, command line)
↓
Consumed by: _PrepareCollectDeclaredReferences target
↓
Passed to: CollectDeclaredReferencesTask
↓
Resolved to: Assembly paths, package information
↓
Written to: _ReferenceTrimmer_DeclaredReferences.tsv
↓
Read by: ReferenceTrimmerAnalyzer
↓
Analyzed and: Diagnostics emitted
```
--------------------------------
### NuGetRestoreTargets Property
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Specifies the directory path to NuGet restore target files required for parsing the lock file.
```csharp
public string? NuGetRestoreTargets { get; set; }
```
--------------------------------
### RT0001 Resolution Options
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/errors.md
Provides methods to remove, suppress, or mark a bare reference as used.
```xml
```
```xml
```
```xml
```
--------------------------------
### Define ForwardingLogger class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
The ForwardingLogger class implements the IForwardingLogger interface for distributed MSBuild logging.
```csharp
public sealed class ForwardingLogger : IForwardingLogger
```
--------------------------------
### Register Distributed Loggers via MSBuild
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-loggers.md
Use the -distributedlogger parameter to register the central and forwarding loggers during an MSBuild execution.
```bash
msbuild MyApp.vcxproj ^
-distributedlogger:ReferenceTrimmer.Loggers.MSVC.CentralLogger,path/to/ReferenceTrimmer.Loggers.MSVC.dll * ^
ReferenceTrimmer.Loggers.MSVC.ForwardingLogger,path/to/ReferenceTrimmer.Loggers.MSVC.dll
```
--------------------------------
### Define CollectDeclaredReferences Target
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Defines the target that invokes the collection task to scan project references.
```xml
```
--------------------------------
### Invoke CollectDeclaredReferences MSBuild Task
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Configures the task within an MSBuild target, mapping project properties and item groups to task inputs.
```xml
```
--------------------------------
### Define ReferenceTrimmerAnalyzer class
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-analyzer.md
The analyzer class definition decorated with supported languages.
```csharp
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public class ReferenceTrimmerAnalyzer : DiagnosticAnalyzer
```
--------------------------------
### Force Cache Invalidation
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Executes a clean and build cycle to force the task to re-run by bypassing the input cache.
```bash
msbuild /p:EnableReferenceTrimmerDiagnostics=true /t:Clean /t:Build
```
--------------------------------
### Mark References as Used with TreatAsUsed
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Marks a reference as always needed to suppress all ReferenceTrimmer diagnostics for that item.
```xml
```
```xml
```
--------------------------------
### Suppress ReferenceTrimmer Warnings
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/api-reference-task.md
Use the NoWarn attribute on Reference or ProjectReference items to ignore specific warning codes, or use TreatAsUsed on PackageReference to suppress all warnings for that package.
```xml
```
--------------------------------
### Suppress Documentation Warnings
Source: https://github.com/dfederm/referencetrimmer/blob/main/_autodocs/configuration.md
Suppresses common XML documentation warnings that may arise when enabling documentation generation.
```xml
true$(NoWarn);CS1591;SA1600
```