# Trimming Compiler Output in .NET .NET compiler can trim assemblies in .NET Core and later to remove unused code. This will significantly reduce the size of compiled assemblies. Whether or not a piece of code is used is determined statically, meaning that trimming may break any reflection code. This is why it is recommended to enable trimming in when building the app and not just publishing it (so that it can be properly tested during development). ## MSBuild Properties | Property | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `PublishTrimmed` | Enables trimming. Make sure to include this in the project, so that it applies during build too (and not just publish). | | `IsTrimmable` | Indicates that an assembly should be trimmed. This is set on all framework assemblies. | | `TrimMode` | Either `link` or `copyused`. `link` will trim all unused members. `copyused` will trim entire assemblies (unless at least one member is used). `link` is default in .NET 6+, `copyused` is default in earlier .NET 5 and earlier. | | `SuppressTrimAnalysisWarnings` | Set to false to include any warnings about code that could be potentially broken by trimming. | | `EnableTrimAnalyzer` | Enables a Roslyn analyzer for trimming issues. Enabled by default in .NET 6+. | ## Sources - [[Trimming Options - .NET]] - [[Trim Self-Contained Applications - .NET]]