[Trimming] Fix ILLink warnings in source generated code#21054
Merged
jonathanpeppers merged 3 commits intodotnet:net9.0from Mar 11, 2024
Merged
Conversation
Member
Author
|
This is probably not the right fix. XamlC runs before ILLink so by the time ILLink processes the assembly, the |
Member
Author
|
I assumed that the warnings are produced by ILLink, but they are in fact produced by Csc (or by an analyzer during C# compilation). This PR is needed after all. |
Co-authored-by: Jonathan Peppers <[email protected]>
jonathanpeppers
previously approved these changes
Mar 6, 2024
vitek-karas
reviewed
Mar 7, 2024
|
|
||
| sb.AppendLine("\t\tprivate void InitializeComponent()"); | ||
| sb.AppendLine("\t\t{"); | ||
| sb.AppendLine("#pragma warning disable IL2026 // The body of InitializeComponent will be replaced by XamlC so LoadFromXaml will never be called in production builds"); |
Member
There was a problem hiding this comment.
I think source suppression would probably work:
dotnet new maui-lib- Have one view or page with XAML
dotnet build -c Release-> would run XamlC- Any consuming app would have no warnings?
Member
Author
There was a problem hiding this comment.
Yes, XamlC will replace the body of InitializeComponent in that case.
jonathanpeppers
approved these changes
Mar 7, 2024
StephaneDelcroix
approved these changes
Mar 11, 2024
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description of Change
ILLinkTrim analyzer is reporting the following warnings:It is safe to suppress the warnings in the
InitializeComponentmethod because its method body will be replaced withXamlCin Release builds.Issues Fixed
Contributes to #19397
/cc @jonathanpeppers @vitek-karas @StephaneDelcroix