You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/deploying/trimming/trimming-options.md
+1-67Lines changed: 1 addition & 67 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Trimming options
3
3
description: Learn how to control trimming of self-contained apps using MSBuild properties. For example, set trimming granularity or suppress trim analysis warnings.
4
4
author: sbomer
5
5
ms.author: svbomer
6
-
ms.date: 08/29/2024
6
+
ms.date: 05/01/2025
7
7
ms.topic: reference
8
8
---
9
9
@@ -24,74 +24,8 @@ Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other option
24
24
25
25
Place this setting in the project file to ensure that the setting applies during `dotnet build`, not just `dotnet publish`.
26
26
27
-
This setting enables trimming and trims all assemblies by default. In .NET 6, only assemblies that opted-in to trimming via `[AssemblyMetadata("IsTrimmable", "True")]` (added in projects that set `<IsTrimmable>true</IsTrimmable>`) were trimmed by default. You can return to the previous behavior by using `<TrimMode>partial</TrimMode>`.
28
-
29
27
This setting also enables the trim-compatibility [Roslyn analyzer](#roslyn-analyzer) and disables [features that are incompatible with trimming](#framework-features-disabled-when-trimming).
30
28
31
-
## Trimming granularity
32
-
33
-
Use the `TrimMode` property to set the trimming granularity to either `partial` or `full`. The default setting for console apps (and, starting in .NET 8, Web SDK apps) is `full`:
34
-
35
-
```xml
36
-
<TrimMode>full</TrimMode>
37
-
```
38
-
39
-
To only trim assemblies that have opted-in to trimming, set the property to `partial`:
40
-
41
-
```xml
42
-
<TrimMode>partial</TrimMode>
43
-
```
44
-
45
-
If you change the trim mode to `partial`, you can opt-in individual assemblies to trimming by using a `<TrimmableAssembly>` MSBuild item.
46
-
47
-
```xml
48
-
<ItemGroup>
49
-
<TrimmableAssemblyInclude="MyAssembly" />
50
-
</ItemGroup>
51
-
```
52
-
53
-
This is equivalent to setting `[AssemblyMetadata("IsTrimmable", "True")]` when building the assembly.
54
-
55
-
## Root assemblies
56
-
57
-
If an assembly is not trimmed, it's considered "rooted", which means that it and all of its statically understood dependencies will be kept. Additional assemblies can be "rooted" by name (without the `.dll` extension):
58
-
59
-
```xml
60
-
<ItemGroup>
61
-
<TrimmerRootAssemblyInclude="MyAssembly" />
62
-
</ItemGroup>
63
-
```
64
-
65
-
## Root descriptors
66
-
67
-
Another way to specify roots for analysis is using an XML file that uses the trimmer [descriptor format](https://github.com/dotnet/runtime/blob/main/docs/tools/illink/data-formats.md#descriptor-format). This lets you root specific members instead of a whole assembly.
68
-
69
-
```xml
70
-
<ItemGroup>
71
-
<TrimmerRootDescriptorInclude="MyRoots.xml" />
72
-
</ItemGroup>
73
-
```
74
-
75
-
For example, `MyRoots.xml` might root a specific method that's dynamically accessed by the application:
Trimming removes IL that's not statically reachable. Apps that use reflection or other patterns that create dynamic dependencies might be broken by trimming. To warn about such patterns, set `<SuppressTrimAnalysisWarnings>` to `false`. This setting will surface warnings about the entire app, including your own code, library code, and framework code.
94
-
95
29
## Roslyn analyzer
96
30
97
31
Setting `PublishTrimmed` in .NET 6+ also enables a Roslyn analyzer that shows a _limited_ set of analysis warnings. You can also enable or disable the analyzer independently of `PublishTrimmed`.
0 commit comments