Skip to content

Commit 85c2676

Browse files
authored
Further opt-in trimming guidance (class libs) (#36127)
1 parent ef60066 commit 85c2676

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

aspnetcore/blazor/host-and-deploy/configure-trimmer.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to control the Intermediate Language (IL) Trimmer when bu
55
monikerRange: '>= aspnetcore-5.0'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 09/08/2025
8+
ms.date: 09/19/2025
99
uid: blazor/host-and-deploy/configure-trimmer
1010
---
1111
# Configure the Trimmer for ASP.NET Core Blazor
@@ -16,6 +16,25 @@ This article explains how to control the Intermediate Language (IL) Trimmer when
1616

1717
Blazor WebAssembly performs [Intermediate Language (IL)](/dotnet/standard/glossary#il) trimming to reduce the size of the published output. Trimming occurs when publishing an app.
1818

19+
## Default trimmer granularity
20+
21+
<!-- UPDATE 10.0 - HOLD until https://github.com/dotnet/aspnetcore/issues/49409
22+
is addressed.
23+
24+
The default trimmer granularity for Blazor apps is `partial`. To trim all assemblies, change the granularity to `full` in the app's project file:
25+
26+
```xml
27+
<PropertyGroup>
28+
<TrimMode>full</TrimMode>
29+
</PropertyGroup>
30+
```
31+
32+
-->
33+
34+
The default trimmer granularity for Blazor apps is `partial`, which means that only core framework libraries and libraries that have explicitly enabled trimming support are trimmed. Full trimming isn't supported.
35+
36+
For more information, see [Trimming options (.NET documentation)](/dotnet/core/deploying/trimming/trimming-options#trimming-granularity).
37+
1938
## Configuration
2039

2140
To configure the IL Trimmer, see the [Trimming options](/dotnet/core/deploying/trimming/trimming-options) article in the .NET Fundamentals documentation, which includes guidance on the following subjects:
@@ -28,17 +47,15 @@ To configure the IL Trimmer, see the [Trimming options](/dotnet/core/deploying/t
2847
* Control symbol trimming and debugger support.
2948
* Set IL Trimmer features for trimming framework library features.
3049

31-
## Default trimmer granularity
32-
33-
The default trimmer granularity for Blazor apps is `partial`. To trim all assemblies, change the granularity to `full` in the app's project file:
50+
When the [trimmer granularity](#default-trimmer-granularity) is `partial`, which is the default value, the IL Trimmer trims the base class library and any other assemblies marked as trimmable. To opt into trimming in any of the app's class library projects, set the `<IsTrimmable>` MSBuild property to `true` in those projects:
3451

3552
```xml
3653
<PropertyGroup>
37-
<TrimMode>full</TrimMode>
54+
<IsTrimmable>true</IsTrimmable>
3855
</PropertyGroup>
3956
```
4057

41-
For more information, see [Trimming options (.NET documentation)](/dotnet/core/deploying/trimming/trimming-options#trimming-granularity).
58+
For guidance that pertains to .NET libraries, see [Prepare .NET libraries for trimming](/dotnet/core/deploying/trimming/prepare-libraries-for-trimming).
4259

4360
## Failure to preserve types used by a published app
4461

@@ -96,7 +113,7 @@ To address lost types, consider adopting one of the following approaches.
96113

97114
### Custom types
98115

99-
Custom types aren't trimmed by Blazor when an app is published (unless explicitly opted in), so we recommend using custom types for JS interop, JSON serialization/deserialization, and other operations that rely on reflection.
116+
To avoid issues with .NET trimming in scenarios that rely on reflection, such as JS interop and JSON serialization, use custom types defined in non-trimmable libraries or preserve the types via linker configuration.
100117

101118
The following modifications create a `StringTuple` type for use by the component.
102119

@@ -123,7 +140,7 @@ The component is modified to use the `StringTuple` type:
123140
+ items = JsonSerializer.Deserialize<List<StringTuple>>(data, options)!;
124141
```
125142

126-
Because custom types aren't trimmed by Blazor when an app is published (unless explicitly opted in), the component works as designed after the app is published.
143+
Because custom types defined in non-trimmable assemblies aren't trimmed by Blazor when an app is published, the component works as designed after the app is published.
127144

128145
:::moniker range=">= aspnetcore-10.0"
129146

@@ -205,4 +222,5 @@ As a workaround in .NET 8, you can add the `_ExtraTrimmerArgs` MSBuild property
205222
## Additional resources
206223

207224
* [Trim self-contained deployments and executables](/dotnet/core/deploying/trimming/trim-self-contained)
225+
* [Prepare .NET libraries for trimming](/dotnet/core/deploying/trimming/prepare-libraries-for-trimming)
208226
* <xref:blazor/performance/app-download-size#intermediate-language-il-trimming>

0 commit comments

Comments
 (0)