-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make TrimmerDefaultAction public #16865
Conversation
Fixes dotnet#16140 Relevant for dotnet/docs#23766
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Are we ready to expose this publicly? We now have a really easy way to "full trim" your app. Are we ready to support this mode? |
That would be my recommendation, to get the behavior described in the WIP library trimming docs:
I can note that this isn't recommended for app authors yet (or just not mention it anywhere else in the docs). If we really don't want to expose this I can change the library mode recommendation to: <Target Name="TrimDependencies" BeforeTargets="PrepareForILLink">
<ItemGroup>
<ManagedAssemblyToLink IsTrimmable="true" />
</ItemGroup>
</Target> |
While I do agree that we don't want people to use this too often (as it comes with a relatively high risk), I think that the current way to do this (via target) looks like a big hack. Maybe we should change it so that when this is set, we always enable trim analysis warnings (even if SDK says otherwise). This would also get us the desired behavior where if I'm in Xamarin and I ask for full trimming, I get warnings by default (it being an advanced scenario). |
This sounds like a good default, but I think it should be up to each SDK to decide (instead of the .NET SDK overriding what the Xamarin SDK or user tells us). Xamarin users who have been successful with LinkAll might not be interested in the warnings. I think a good way to accomplish this would be for the Xamarin SDKs to suppress warnings only when |
It's quite unlikely that app that works with LinkAll today (presumably because it also has several things manually persisted) will just work after migration to net6. I think we should enable the warnings, especially if we issue only 1 per assembly by default, for anyone trimming with "link-all" setup. |
I like this idea. 👍. |
Should there be a way to override that default (a way to to turn off warnings when using LinkAll)? |
I would expect the user provided value for |
It might be possible by setting a default in early properties, then detecting if it has been changed after SDK props are imported... but I am not a fan of that pattern. I think just updating the places that set SuppressTrimAnalysisWarnings to true (so they only do it when the TrimmerDefaultAction is copy) is a simpler way to get the behavior we want. |
Alternatively we could change the SDKs to set a private property instead and combine the public property with the private property in one place, taking the TrimmerDefaultAction into consideration. |
Why would not standard warning (1 in this case) suppression work? |
Which "1" warning so you have in mind. The idea is that is I turn on agressive trimming for everything by default I get the detailed warnings - that might be 100s for complex apps. The end of the discussion is if there's a way to suppress them - they are suppresable via NoWarn, but the list is like 80 different warning codes, so not ideal. |
That would work for nuget dependencies of the app, but we still show detailed warnings for app code (with different codes). |
Just to clarify - we would still collapse warnings from nugets, right? |
yes - sorry I didn't make that clear |
I think the scenario is a bit different. You turn it on and you have code you can modify (basically you have multiple ways to resolve the warnings) and you have tons of dependencies you cannot modify. If you are going to publish your app with aggressive trimming all unaddressed warnings are "wrong" and you would like to suppress them. I'd suspect these will come from the nuget assemblies and my understanding is that we are going to fold the trim analysis warning from them by default. Any warnings in the app code can be suppressed with pragma(s) or resolved. |
This is still true with the latest change, and will be the recommended way to suppress warnings (though note that pragmas don't work for trim warnings) - so I think we agree on this. The question is only about
|
df91081
to
15ea85a
Compare
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ILLink.targets
Show resolved
Hide resolved
@@ -30,7 +30,7 @@ Copyright (c) .NET Foundation. All rights reserved. | |||
<PublishTrimmed Condition="'$(PublishTrimmed)' == ''">true</PublishTrimmed> | |||
<TrimMode Condition="'$(TrimMode)' == ''">link</TrimMode> | |||
<TrimmerRemoveSymbols Condition="'$(TrimmerRemoveSymbols)' == ''">false</TrimmerRemoveSymbols> | |||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">true</SuppressTrimAnalysisWarnings> | |||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(TrimmerDefaultAction)' != 'link'">true</SuppressTrimAnalysisWarnings> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that these .props
files get evalutated before the .csproj is evaluated.
So if I have a Blazor or Web .csproj that contains:
<TrimmerDefaultAction>true</TrimmerDefaultAction>
This check is going to run too soon, and the warnings will still be suppressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this, I moved it to the targets.
So that the condition takes into account properties set in the project file.
- Don't require un-suppressing warnings, as this is now implied by TrimmerDefaultAction=link: dotnet/sdk#16865 - Clarify why publishing an app is necessary for library warnings
* Document new linker options and trimming libraries * Fix TOC * Document EnableTrimAnalyzer And fix typos, links * PR feedback - Move sample up - Call out TrimMode link default - Clarify app vs library - Publish Release * Change title to "Preparing libraries for trimming" * PR feedback - Fix typo - Avoid referencing sections with "above/below" * PR feedback Add code snippet for examples after annotation * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * Update docs/core/deploying/trimming-options.md Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * PR feedback - Fix links - Clarify which assemblies are trimmed by default - Clarify which assemblies are affected by per-assembly metadata * PR feedback - Change example to call reflection directly - Avoid mentioning .NET 5 - Point out benefits of Roslyn analyzer - Avoid Foo/Bar - Recommend not annotating virtuals * Add advanced section Which mentions UnconditionalSuppressMessage * Remove whitespace * PR feedback - Clarify why we need an exe - Improve comments in sample csproj * More comments * PR feedback Simplify wording * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/trimming-options.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/trimming-options.md Co-authored-by: David Pine <david.pine@microsoft.com> * Add intro and fix links * Rename file to match title * Update trimming-options.md * Apply suggestions from code review * PR feedback - Don't require un-suppressing warnings, as this is now implied by TrimmerDefaultAction=link: dotnet/sdk#16865 - Clarify why publishing an app is necessary for library warnings Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> Co-authored-by: David Pine <david.pine@microsoft.com>
* Document new linker options and trimming libraries * Fix TOC * Document EnableTrimAnalyzer And fix typos, links * PR feedback - Move sample up - Call out TrimMode link default - Clarify app vs library - Publish Release * Change title to "Preparing libraries for trimming" * PR feedback - Fix typo - Avoid referencing sections with "above/below" * PR feedback Add code snippet for examples after annotation * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * Update docs/core/deploying/trimming-options.md Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * PR feedback - Fix links - Clarify which assemblies are trimmed by default - Clarify which assemblies are affected by per-assembly metadata * PR feedback - Change example to call reflection directly - Avoid mentioning .NET 5 - Point out benefits of Roslyn analyzer - Avoid Foo/Bar - Recommend not annotating virtuals * Add advanced section Which mentions UnconditionalSuppressMessage * Remove whitespace * PR feedback - Clarify why we need an exe - Improve comments in sample csproj * More comments * PR feedback Simplify wording * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/trimming-options.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/preparing-libraries-for-trimming.md Co-authored-by: David Pine <david.pine@microsoft.com> * Update docs/core/deploying/trimming-options.md Co-authored-by: David Pine <david.pine@microsoft.com> * Add intro and fix links * Rename file to match title * Update trimming-options.md * Apply suggestions from code review * PR feedback - Don't require un-suppressing warnings, as this is now implied by TrimmerDefaultAction=link: dotnet/sdk#16865 - Clarify why publishing an app is necessary for library warnings Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> Co-authored-by: David Pine <david.pine@microsoft.com>
Fixes #16140
Relevant for dotnet/docs#23766