Skip to content

Add property to add non-file URL resolver support #42387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/core/deploying/native-aot/optimizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Setting `OptimizationPreference` to `Speed` instructs the publishing process to

## Further size optimization options

Since Native AOT deployments imply the use of trimming, it's possible to further improve the size of the application by specifying more [trimming options](../trimming/trimming-options.md). For example, the [Trimming framework library features section](../trimming/trimming-options.md#trimming-framework-library-features) discusses how to disable library features such as globalization.
Since Native AOT deployments imply the use of trimming, it's possible to further improve the size of the application by specifying more [trimming options](../trimming/trimming-options.md). For example, the [Trim framework library features section](../trimming/trimming-options.md#trim-framework-library-features) discusses how to disable library features such as globalization.
76 changes: 22 additions & 54 deletions docs/core/deploying/trimming/trimming-options.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: Trimming options
description: Learn how to control trimming of self-contained apps.
description: Learn how to control trimming of self-contained apps using MSBuild properties. For example, set trimming granularity or suppress trim analysis warnings.
author: sbomer
ms.author: svbomer
ms.date: 06/26/2024
ms.date: 08/29/2024
ms.topic: reference
zone_pivot_groups: dotnet-version
---

# Trimming options

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).
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).

Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other options are available only in .NET 5 and later versions.
Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other options are available in .NET 5 and later versions.

## Enable trimming

Expand Down Expand Up @@ -198,59 +198,27 @@ Symbols are usually trimmed to match the trimmed assemblies. You can also remove

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).

## Trimming framework library features
## Trim framework library features

Several feature areas of the framework libraries come with trimmer directives that make it possible to remove the code for disabled features.

- `<AutoreleasePoolSupport>false</AutoreleasePoolSupport>` (default)

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.

- `<DebuggerSupport>false</DebuggerSupport>`

Remove code that enables better debugging experiences. This setting also [removes symbols](#remove-symbols).

- `<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>`

Remove BinaryFormatter serialization support. For more information, see [BinaryFormatter serialization methods are obsolete](../../compatibility/serialization/5.0/binaryformatter-serialization-obsolete.md).

- `<EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>`

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).

- `<EventSourceSupport>false</EventSourceSupport>`

Remove EventSource related code or logic.

- `<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>`

Remove code related to diagnostics support for System.Net.Http.

- `<InvariantGlobalization>true</InvariantGlobalization>`

Remove globalization-specific code and data. For more information, see [Invariant mode](../../runtime-config/globalization.md#invariant-mode).

- `<MetadataUpdaterSupport>false</MetadataUpdaterSupport>`

Remove metadata update-specific logic related to hot reload.

- `<MetricsSupport>false</MetricsSupport>`

Removes support for System.Diagnostics.Metrics instrumentation.

- `<StackTraceSupport>false</StackTraceSupport>` (.NET 8+)

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.

- `<UseNativeHttpHandler>true</UseNativeHttpHandler>`

Use the default platform implementation of HttpMessageHandler for Android/iOS and remove the managed implementation.

- `<UseSystemResourceKeys>true</UseSystemResourceKeys>`

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.

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.
| MSBuild property | Description |
| - | - |
| `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. |
| `DebuggerSupport` | When set to `false`, removes code that enables better debugging experiences. This setting also [removes symbols](#remove-symbols). |
| `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). |
| `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). |
| `EventSourceSupport` | When set to `false`, removes EventSource-related code and logic. |
| `HttpActivityPropagationSupport` | When set to `false`, removes code related to diagnostics support for <xref:System.Net.Http>. |
| `InvariantGlobalization` | When set to `true`, removes globalization-specific code and data. For more information, see [Invariant mode](../../runtime-config/globalization.md#invariant-mode). |
| `MetadataUpdaterSupport` | When set to `false`, removes metadata update&ndash;specific logic related to hot reload. |
| `MetricsSupport` | When set to `false`, removes support for <xref:System.Diagnostics.Metrics> instrumentation. |
| `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. |
| `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. |
| `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. |
| `XmlResolverIsNetworkingEnabledByDefault` (.NET 8+) | When set to `false`, removes support for resolving non-file URLs in <xref:System.Xml>. Only file-system resolving is supported. |

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.

## Framework features disabled when trimming

Expand Down
Loading