Skip to content

chore: enable IL trim analyzer on Web.Client project#447

Merged
bruno-garcia merged 3 commits into
mainfrom
enable-trim-analyzer
Feb 14, 2026
Merged

chore: enable IL trim analyzer on Web.Client project#447
bruno-garcia merged 3 commits into
mainfrom
enable-trim-analyzer

Conversation

@bruno-garcia

Copy link
Copy Markdown
Member

Summary

  • Enables EnableTrimAnalyzer and SuppressTrimAnalysisWarnings on the Blazor WASM project so trim-unsafe patterns surface as build errors (via TreatWarningsAsErrors) rather than only manifesting as runtime failures after publish
  • Suppresses IL2110/IL2111 (false positives from Blazor framework Razor codegen for Router.NotFoundPage and LayoutView.Layout)
  • Suppresses IL2026 at PersistentComponentState.TryTakeFromJson<string>/PersistAsJson call sites — string serialization is trim-safe but the API lacks source-generator overloads

Why scoped to Web.Client only

The trim analyzer was initially tested in Directory.Build.props (repo-wide), but server-side projects like NuGetTrends.Data use EF Core which is inherently not trim-compatible. Since only the Blazor WASM client is published with trimming enabled, the analyzer is scoped there.

Test plan

  • dotnet build passes with 0 warnings and 0 errors
  • All 385 unit tests pass
  • CI passes

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings February 14, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances build-time safety for the Blazor WASM client by enabling the IL trim analyzer, which surfaces trim-unsafe patterns as compile errors rather than runtime failures after publish. The changes include enabling EnableTrimAnalyzer, suppressing known false positives from Blazor framework Razor code generation (IL2110/IL2111), and adding targeted inline suppressions for legitimate IL2026 warnings in state persistence code that uses a trim-safe pattern.

Changes:

  • Enable IL trim analyzer on Web.Client project with EnableTrimAnalyzer=true and SuppressTrimAnalysisWarnings=false
  • Suppress IL2110/IL2111 warnings (false positives from Blazor Router/LayoutView Razor codegen) at project level
  • Add inline IL2026 suppressions for PersistentComponentState API calls that use trim-safe string serialization with source generators

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/NuGetTrends.Web.Client/NuGetTrends.Web.Client.csproj Enables trim analyzer and suppresses framework-generated false positive warnings (IL2110/IL2111)
src/NuGetTrends.Web.Client/Shared/TrendingPackages.razor Adds inline IL2026 suppressions for trim-safe PersistentComponentState string serialization calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… 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>
Comment thread src/NuGetTrends.Web.Client/Shared/TrendingPackages.razor Outdated
#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>
@bruno-garcia

Copy link
Copy Markdown
Member Author

Review comments addressed

# Comment Author Verdict Action
1 Copilot summary — no actionable comments copilot-pull-request-reviewer[bot] N/A No action needed
2 #pragma warning disable IL2026 is ineffective for ILLink sentry[bot] Accepted Replaced with [UnconditionalSuppressMessage] which is persisted in IL and works for both the Roslyn analyzer and the ILLink trimmer

@bruno-garcia bruno-garcia merged commit de245f1 into main Feb 14, 2026
4 checks passed
@bruno-garcia bruno-garcia deleted the enable-trim-analyzer branch February 14, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants