Muokkaa

Jaa


Configure the Trimmer for ASP.NET Core Blazor

Note

This isn't the latest version of this article. For the current release, see the .NET 9 version of this article.

Warning

This version of ASP.NET Core is no longer supported. For more information, see the .NET and .NET Core Support Policy. For the current release, see the .NET 9 version of this article.

Important

This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

For the current release, see the .NET 9 version of this article.

This article explains how to control the Intermediate Language (IL) Trimmer when building a Blazor app.

Blazor WebAssembly performs Intermediate Language (IL) trimming to reduce the size of the published output. Trimming occurs when publishing an app.

Trimming may have detrimental effects for the published app. In apps that use reflection, the IL Trimmer often can't determine the required types for runtime reflection and trim them away. For example, complex framework types for JS interop, such as KeyValuePair, might be trimmed and not available at runtime for JS interop calls. In these cases, we recommend creating your own custom types instead. The IL Trimmer is also unable to react to an app's dynamic behavior at runtime. To ensure the trimmed app works correctly once deployed, test published output frequently while developing.

Configuration

To configure the IL Trimmer, see the Trimming options article in the .NET Fundamentals documentation, which includes guidance on the following subjects:

  • Disable trimming for the entire app with the <PublishTrimmed> property in the project file.
  • Control how aggressively unused IL is discarded by the IL Trimmer.
  • Stop the IL Trimmer from trimming specific assemblies.
  • "Root" assemblies for trimming.
  • Surface warnings for reflected types by setting the <SuppressTrimAnalysisWarnings> property to false in the project file.
  • Control symbol trimming and debugger support.
  • Set IL Trimmer features for trimming framework library features.

Default trimmer granularity

The default trimmer granularity for Blazor apps is partial. To trim all assemblies, change the granularity to full in the app's project file:

<ItemGroup>
  <TrimMode>full</TrimMode>
</ItemGroup>

For more information, see Trimming options (.NET documentation).

Additional resources