You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/host-and-deploy/configure-trimmer.md
+26-8Lines changed: 26 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how to control the Intermediate Language (IL) Trimmer when bu
5
5
monikerRange: '>= aspnetcore-5.0'
6
6
ms.author: wpickett
7
7
ms.custom: mvc
8
-
ms.date: 09/08/2025
8
+
ms.date: 09/19/2025
9
9
uid: blazor/host-and-deploy/configure-trimmer
10
10
---
11
11
# Configure the Trimmer for ASP.NET Core Blazor
@@ -16,6 +16,25 @@ This article explains how to control the Intermediate Language (IL) Trimmer when
16
16
17
17
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.
18
18
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
+
19
38
## Configuration
20
39
21
40
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
28
47
* Control symbol trimming and debugger support.
29
48
* Set IL Trimmer features for trimming framework library features.
30
49
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:
34
51
35
52
```xml
36
53
<PropertyGroup>
37
-
<TrimMode>full</TrimMode>
54
+
<IsTrimmable>true</IsTrimmable>
38
55
</PropertyGroup>
39
56
```
40
57
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).
42
59
43
60
## Failure to preserve types used by a published app
44
61
@@ -96,7 +113,7 @@ To address lost types, consider adopting one of the following approaches.
96
113
97
114
### Custom types
98
115
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.
100
117
101
118
The following modifications create a `StringTuple` type for use by the component.
102
119
@@ -123,7 +140,7 @@ The component is modified to use the `StringTuple` type:
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.
127
144
128
145
:::moniker range=">= aspnetcore-10.0"
129
146
@@ -205,4 +222,5 @@ As a workaround in .NET 8, you can add the `_ExtraTrimmerArgs` MSBuild property
205
222
## Additional resources
206
223
207
224
*[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)
0 commit comments