-
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
Change linker defaults to "link" with warnings #16327
Changes from all commits
81eaf67
7da4001
ee37188
2e17ed7
d93be0f
0a9d59c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,13 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<CustomResourceTypesSupport>false</CustomResourceTypesSupport> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(EnableTrimAnalyzer)' == 'true' or '$(PublishTrimmed)' == 'true'"> | ||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">true</SuppressTrimAnalysisWarnings> | ||
<PropertyGroup Condition="'$(SuppressTrimAnalysisWarnings)' == '' And ('$(EnableTrimAnalyzer)' == 'true' Or '$(PublishTrimmed)' == 'true')"> | ||
<!-- Trim analysis warnings are suppressed for .NET < 6. --> | ||
<SuppressTrimAnalysisWarnings Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">true</SuppressTrimAnalysisWarnings> | ||
<!-- Suppress for WPF/WinForms --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true'">true</SuppressTrimAnalysisWarnings> | ||
<!-- Otherwise, for .NET 6+, warnings are on by default --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">false</SuppressTrimAnalysisWarnings> | ||
</PropertyGroup> | ||
|
||
<!-- Suppress warnings produced by the linker or by the ILLink Roslyn analyzer. Warnings produced | ||
|
@@ -178,14 +183,18 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<ILLinkWarningLevel Condition=" '$(ILLinkWarningLevel)' == '' ">0</ILLinkWarningLevel> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<ILLinkTreatWarningsAsErrors Condition=" '$(ILLinkTreatWarningsAsErrors)' == '' ">$(TreatWarningsAsErrors)</ILLinkTreatWarningsAsErrors> | ||
<_ExtraTrimmerArgs>--skip-unresolved true $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs> | ||
<!-- Defaults for .NET < 6 --> | ||
<PropertyGroup Condition=" $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0')) "> | ||
<TrimMode Condition=" '$(TrimMode)' == '' ">copyused</TrimMode> | ||
<!-- For .NET < 6, the defaults are the same regardless of whether the assembly has an IsTrimmable attribute. (The attribute didn't exist until .NET 6.) --> | ||
<_TrimmerDefaultAction Condition=" $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0')) ">$(TrimMode)</_TrimmerDefaultAction> | ||
<!-- Action is the same regardless of whether the assembly has an IsTrimmable attribute. (The attribute didn't exist until .NET 6.) --> | ||
<_TrimmerDefaultAction>$(TrimMode)</_TrimmerDefaultAction> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TrimMode Condition=" '$(TrimMode)' == '' ">link</TrimMode> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: I wonder if we should have a message now whenever 'link' is set and warnings are on just so the user understands why all of a sudden their app started to have all of these warnings that it didn't have in the previous version of the sdk... Doesn't need to happen on this PR but perhaps it is something we should just consider as a feature for better experience. Maybe we could even just add this note on the message that we already print out today where we say that linking may affect functionality of your app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. We're already planning to improve the warning experience in P4 - we want to "collapse" them by assembly to be less noisy, which should make it more obvious what they're about (so you would only get a warning like "SomeAssembly is not annotated for trimming."). I think that plus the existing message we print out, and that trimming is still considered "preview" will make it clear enough - and I'm also happy to change the message. How about this? I guess we could also change the message only for .NET6+ (or condition it based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I'm fine with whatever is decided. My comment here was more around the fact that we are now actually linking very differently the apps by default, so imagine a person who was using a previous version of the SDK, tested their app at runtime due to our message and ensured it ran fine, and then update the SDK but wouldn't re-test as they had already tested their app before and the warning they got is the same. I'm sure I'm overthinking this 😆 so again not really required for you to change things as they are now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's not correct as it really depends on SDKs and the user settings.
I think we should go with a simple message not to add all sort of ifs/whens. "Optimizing managed assemblies for size. Unresolved illink warnings could break the application (aka.ms/dotnet-illink)" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree simple is better. The issue with "Unresolved illink warnings could break the application" is that the warnings are disabled when targeting net5.0, but linking could still break the app. FWIW, this is the current message - maybe it's good enough as-is? The aka.ms link should make it easy enough to find the options for turning on/off the warnings. "Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really like to avoid using the word "publishing" and we are running the illink before we run the tests sometimes too, hence "Be sure to test after publishing." sentence is not really helpful. |
||
<!-- For .NET 6+, assemblies without IsTrimmable attribute get the "copy" action. --> | ||
<_TrimmerDefaultAction Condition=" '$(_TrimmerDefaultAction)' == '' ">copy</_TrimmerDefaultAction> | ||
<ILLinkTreatWarningsAsErrors Condition=" '$(ILLinkTreatWarningsAsErrors)' == '' ">$(TreatWarningsAsErrors)</ILLinkTreatWarningsAsErrors> | ||
<_ExtraTrimmerArgs>--skip-unresolved true $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs> | ||
</PropertyGroup> | ||
|
||
<!-- Suppress warnings produced by the linker. Any warnings shared with the analyzer should be | ||
|
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.
Should we check TFM as well? Looks like we are only checking framework version but not that they are targeting Core. I can't really think now of a case where it would matter since other TFMs like .NET Framework don't really have a 6.0 version, but I might be not considering some.
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.
I asked a similar question here: #16094 (comment)
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.
Yup, we already check for netcoreapp in ILLink. Technically these global properties could be defined (but unused) on .NET Framework if someone sets "PublishTrimmed"... if anything, maybe we should be emitting a warning if someone sets PublishTrimmed while targeting .NET Framework as it will currently do nothing.