|
1 | 1 | --- |
2 | 2 | title: Trimming options |
3 | | -description: Learn how to control trimming of self-contained apps. |
| 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: 06/26/2024 |
| 6 | +ms.date: 08/29/2024 |
7 | 7 | ms.topic: reference |
8 | 8 | zone_pivot_groups: dotnet-version |
9 | 9 | --- |
10 | 10 |
|
11 | 11 | # Trimming options |
12 | 12 |
|
13 | | -The following MSBuild properties and items influence the behavior of [trimmed self-contained deployments](trim-self-contained.md). Some of the options mention `ILLink`, which is the name of the underlying tool that implements trimming. For more information about the underlying tool, see the [Trimmer documentation](https://github.com/dotnet/runtime/tree/main/docs/tools/illink). |
| 13 | +The MSBuild properties and items described in this article influence the behavior of [trimmed, self-contained deployments](trim-self-contained.md). Some of the options mention `ILLink`, which is the name of the underlying tool that implements trimming. For more information about the underlying tool, see the [Trimmer documentation](https://github.com/dotnet/runtime/tree/main/docs/tools/illink). |
14 | 14 |
|
15 | | -Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other options are available only in .NET 5 and later versions. |
| 15 | +Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other options are available in .NET 5 and later versions. |
16 | 16 |
|
17 | 17 | ## Enable trimming |
18 | 18 |
|
@@ -198,59 +198,27 @@ Symbols are usually trimmed to match the trimmed assemblies. You can also remove |
198 | 198 |
|
199 | 199 | The SDK also makes it possible to disable debugger support using the property `DebuggerSupport`. When debugger support is disabled, trimming removes symbols automatically (`TrimmerRemoveSymbols` will default to true). |
200 | 200 |
|
201 | | -## Trimming framework library features |
| 201 | +## Trim framework library features |
202 | 202 |
|
203 | 203 | Several feature areas of the framework libraries come with trimmer directives that make it possible to remove the code for disabled features. |
204 | 204 |
|
205 | | -- `<AutoreleasePoolSupport>false</AutoreleasePoolSupport>` (default) |
206 | | - |
207 | | - Remove code that creates autorelease pools on supported platforms. See [AutoreleasePool for managed threads](../../runtime-config/threading.md#autoreleasepool-for-managed-threads). This is the default for the .NET SDK. |
208 | | - |
209 | | -- `<DebuggerSupport>false</DebuggerSupport>` |
210 | | - |
211 | | - Remove code that enables better debugging experiences. This setting also [removes symbols](#remove-symbols). |
212 | | - |
213 | | -- `<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>` |
214 | | - |
215 | | - Remove BinaryFormatter serialization support. For more information, see [BinaryFormatter serialization methods are obsolete](../../compatibility/serialization/5.0/binaryformatter-serialization-obsolete.md). |
216 | | - |
217 | | -- `<EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>` |
218 | | - |
219 | | - Remove insecure UTF-7 encoding code. For more information, see [UTF-7 code paths are obsolete](../../compatibility/core-libraries/5.0/utf-7-code-paths-obsolete.md). |
220 | | - |
221 | | -- `<EventSourceSupport>false</EventSourceSupport>` |
222 | | - |
223 | | - Remove EventSource related code or logic. |
224 | | - |
225 | | -- `<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>` |
226 | | - |
227 | | - Remove code related to diagnostics support for System.Net.Http. |
228 | | - |
229 | | -- `<InvariantGlobalization>true</InvariantGlobalization>` |
230 | | - |
231 | | - Remove globalization-specific code and data. For more information, see [Invariant mode](../../runtime-config/globalization.md#invariant-mode). |
232 | | - |
233 | | -- `<MetadataUpdaterSupport>false</MetadataUpdaterSupport>` |
234 | | - |
235 | | - Remove metadata update-specific logic related to hot reload. |
236 | | - |
237 | | -- `<MetricsSupport>false</MetricsSupport>` |
238 | | - |
239 | | - Removes support for System.Diagnostics.Metrics instrumentation. |
240 | | - |
241 | | -- `<StackTraceSupport>false</StackTraceSupport>` (.NET 8+) |
242 | | - |
243 | | - Remove support for generating stack traces (for example, <xref:System.Environment.StackTrace?displayProperty=nameWithType>, or <xref:System.Exception.ToString%2A?displayProperty=nameWithType>) by the runtime. The amount of information that will be removed from stack trace strings may depend on other deployment options. This option does not affect stack traces generated by debuggers. |
244 | | - |
245 | | -- `<UseNativeHttpHandler>true</UseNativeHttpHandler>` |
246 | | - |
247 | | - Use the default platform implementation of HttpMessageHandler for Android/iOS and remove the managed implementation. |
248 | | - |
249 | | -- `<UseSystemResourceKeys>true</UseSystemResourceKeys>` |
250 | | - |
251 | | - Strip exception messages for `System.*` assemblies. When an exception is thrown from a `System.*` assembly, the message is a simplified resource ID instead of the full message. |
252 | | - |
253 | | -These properties cause the related code to be trimmed and also disable features via the [runtimeconfig](../../runtime-config/index.md) file. For more information about these properties, including the corresponding *runtimeconfig* options, see [feature switches](https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md). Some SDKs might have default values for these properties. |
| 205 | +| MSBuild property | Description | |
| 206 | +| - | - | |
| 207 | +| `AutoreleasePoolSupport` | When set to `false`, removes code that creates [autorelease pools](../../runtime-config/threading.md#autoreleasepool-for-managed-threads) on supported platforms. `false` is the default for the .NET SDK. | |
| 208 | +| `DebuggerSupport` | When set to `false`, removes code that enables better debugging experiences. This setting also [removes symbols](#remove-symbols). | |
| 209 | +| `EnableUnsafeBinaryFormatterSerialization` | When set to `false`, removes BinaryFormatter serialization support. For more information, see [BinaryFormatter serialization methods are obsolete](../../compatibility/serialization/5.0/binaryformatter-serialization-obsolete.md) and [In-box BinaryFormatter implementation removed and always throws](../../compatibility/serialization/9.0/binaryformatter-removal.md). | |
| 210 | +| `EnableUnsafeUTF7Encoding` | When set to `false`, removes insecure UTF-7 encoding code. For more information, see [UTF-7 code paths are obsolete](../../compatibility/core-libraries/5.0/utf-7-code-paths-obsolete.md). | |
| 211 | +| `EventSourceSupport` | When set to `false`, removes EventSource-related code and logic. | |
| 212 | +| `HttpActivityPropagationSupport` | When set to `false`, removes code related to diagnostics support for <xref:System.Net.Http>. | |
| 213 | +| `InvariantGlobalization` | When set to `true`, removes globalization-specific code and data. For more information, see [Invariant mode](../../runtime-config/globalization.md#invariant-mode). | |
| 214 | +| `MetadataUpdaterSupport` | When set to `false`, removes metadata update–specific logic related to hot reload. | |
| 215 | +| `MetricsSupport` | When set to `false`, removes support for <xref:System.Diagnostics.Metrics> instrumentation. | |
| 216 | +| `StackTraceSupport` (.NET 8+) | When set to `false`, removes support for generating stack traces (for example, <xref:System.Environment.StackTrace?displayProperty=nameWithType> or <xref:System.Exception.ToString%2A?displayProperty=nameWithType>) by the runtime. The amount of information that is removed from stack trace strings might depend on other deployment options. This option does not affect stack traces generated by debuggers. | |
| 217 | +| `UseNativeHttpHandler` | When set to `true`, uses the default platform implementation of <xref:System.Net.Http.HttpMessageHandler> for Android and iOS and removes the managed implementation. | |
| 218 | +| `UseSystemResourceKeys` | When set to `true`, strips exception messages for `System.*` assemblies. When an exception is thrown from a `System.*` assembly, the message is a simplified resource ID instead of the full message. | |
| 219 | +| `XmlResolverIsNetworkingEnabledByDefault` (.NET 8+) | When set to `false`, removes support for resolving non-file URLs in <xref:System.Xml>. Only file-system resolving is supported. | |
| 220 | + |
| 221 | +These properties cause the related code to be trimmed and also disable features via the [runtimeconfig](../../runtime-config/index.md) file. For more information about these properties, including the corresponding _runtimeconfig_ options, see [feature switches](https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md). Some SDKs might have default values for these properties. |
254 | 222 |
|
255 | 223 | ## Framework features disabled when trimming |
256 | 224 |
|
|
0 commit comments