chore: enable IL trim analyzer on Web.Client project#447
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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=trueandSuppressTrimAnalysisWarnings=false - Suppress IL2110/IL2111 warnings (false positives from Blazor Router/LayoutView Razor codegen) at project level
- Add inline IL2026 suppressions for
PersistentComponentStateAPI 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>
#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>
Member
Author
Review comments addressed
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EnableTrimAnalyzerandSuppressTrimAnalysisWarningson the Blazor WASM project so trim-unsafe patterns surface as build errors (viaTreatWarningsAsErrors) rather than only manifesting as runtime failures after publishRouter.NotFoundPageandLayoutView.Layout)PersistentComponentState.TryTakeFromJson<string>/PersistAsJsoncall sites —stringserialization is trim-safe but the API lacks source-generator overloadsWhy scoped to Web.Client only
The trim analyzer was initially tested in
Directory.Build.props(repo-wide), but server-side projects likeNuGetTrends.Datause 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 buildpasses with 0 warnings and 0 errors🤖 Generated with Claude Code