Skip to content

Commit d38c745

Browse files
authored
Update trimming-options.md (#45945)
1 parent ff8d253 commit d38c745

File tree

1 file changed

+1
-67
lines changed

1 file changed

+1
-67
lines changed

docs/core/deploying/trimming/trimming-options.md

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Trimming options
33
description: Learn how to control trimming of self-contained apps using MSBuild properties. For example, set trimming granularity or suppress trim analysis warnings.
44
author: sbomer
55
ms.author: svbomer
6-
ms.date: 08/29/2024
6+
ms.date: 05/01/2025
77
ms.topic: reference
88
---
99

@@ -24,74 +24,8 @@ Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other option
2424
2525
Place this setting in the project file to ensure that the setting applies during `dotnet build`, not just `dotnet publish`.
2626

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-
2927
This setting also enables the trim-compatibility [Roslyn analyzer](#roslyn-analyzer) and disables [features that are incompatible with trimming](#framework-features-disabled-when-trimming).
3028

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-
<TrimmableAssembly Include="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-
<TrimmerRootAssembly Include="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-
<TrimmerRootDescriptor Include="MyRoots.xml" />
72-
</ItemGroup>
73-
```
74-
75-
For example, `MyRoots.xml` might root a specific method that's dynamically accessed by the application:
76-
77-
```xml
78-
<linker>
79-
<assembly fullname="MyAssembly">
80-
<type fullname="MyAssembly.MyClass">
81-
<method name="DynamicallyAccessedMethod" />
82-
</type>
83-
</assembly>
84-
</linker>
85-
```
86-
87-
## Analysis warnings
88-
89-
- `<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>`
90-
91-
Enable trim analysis warnings.
92-
93-
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-
9529
## Roslyn analyzer
9630

9731
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

Comments
 (0)