Skip to content

Commit de245f1

Browse files
bruno-garciaclaude
andauthored
chore: enable IL trim analyzer on Web.Client project (#447)
* chore: enable IL trim analyzer on Web.Client to catch trim issues at build time Enables EnableTrimAnalyzer and SuppressTrimAnalysisWarnings on the Blazor WASM project so trim-unsafe patterns surface as build errors (via TreatWarningsAsErrors) rather than runtime failures after publish. Suppresses IL2110/IL2111 (framework Razor codegen false positives) and IL2026 at PersistentComponentState call sites (string serialization is trim-safe but the API lacks source-generator overloads). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove SuppressTrimAnalysisWarnings which also affects ILLink at publish SuppressTrimAnalysisWarnings=false surfaces warnings from the ILLink trimmer during publish (IL2026/IL2104 from third-party assemblies), not just from the Roslyn analyzer. EnableTrimAnalyzer alone is sufficient for build-time detection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * address review: replace #pragma with [UnconditionalSuppressMessage] #pragma warning disable only works for the Roslyn analyzer and is ignored by ILLink during publish. UnconditionalSuppressMessage is persisted in IL and respected by both. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 05d9488 commit de245f1

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/NuGetTrends.Web.Client/NuGetTrends.Web.Client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<Nullable>enable</Nullable>
77
<UseSentryCLI>false</UseSentryCLI>
88
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
9+
<!-- IL trimming: catch trim-unsafe patterns at build time via Roslyn analyzer -->
10+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
11+
<!-- IL2110/IL2111: false positives from Blazor framework Razor codegen (Router, LayoutView) -->
12+
<NoWarn>$(NoWarn);IL2110;IL2111</NoWarn>
913
</PropertyGroup>
1014

1115
<!-- IL trimming: remove unused code from published WASM assemblies -->

src/NuGetTrends.Web.Client/Shared/TrendingPackages.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@using System.Diagnostics.CodeAnalysis
12
@using System.Text.Json
23
@inject HttpClient Http
34
@inject NavigationManager Navigation
@@ -105,6 +106,8 @@
105106
private string? _errorMessage;
106107
private PersistingComponentStateSubscription _persistingSubscription;
107108

109+
[UnconditionalSuppressMessage("Trimming", "IL2026",
110+
Justification = "PersistentComponentState lacks source-generator overloads; serializing string is trim-safe.")]
108111
protected override async Task OnInitializedAsync()
109112
{
110113
_persistingSubscription = PersistentState.RegisterOnPersisting(PersistData);
@@ -121,6 +124,8 @@
121124
}
122125
}
123126

127+
[UnconditionalSuppressMessage("Trimming", "IL2026",
128+
Justification = "PersistentComponentState lacks source-generator overloads; serializing string is trim-safe.")]
124129
private Task PersistData()
125130
{
126131
PersistentState.PersistAsJson(PersistenceKey,

0 commit comments

Comments
 (0)