-
Notifications
You must be signed in to change notification settings - Fork 128
Add more trimming options to TrimMode and change defaults #2856
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
Changes from all commits
774a7b5
d284611
67a526a
6e5faa3
381e390
92f1b11
ea1ea46
06fcb73
17055e1
46518c5
c7f5e88
11e5cd3
83620fa
1d93fe4
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 |
|---|---|---|
|
|
@@ -51,8 +51,8 @@ Copyright (c) .NET Foundation. All rights reserved. | |
| <PropertyGroup Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(PublishTrimmed)' == 'true' And '$(EnableTrimAnalyzer)' != 'true'"> | ||
| <!-- Trim analysis warnings are suppressed for .NET < 6. --> | ||
| <SuppressTrimAnalysisWarnings Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">true</SuppressTrimAnalysisWarnings> | ||
| <!-- Suppress for WPF/WinForms (unless linking everything) --> | ||
| <SuppressTrimAnalysisWarnings Condition="'$(TrimmerDefaultAction)' != 'link' And ('$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true')">true</SuppressTrimAnalysisWarnings> | ||
| <!-- Suppress for WPF/WinForms --> | ||
| <SuppressTrimAnalysisWarnings Condition="'$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true'">true</SuppressTrimAnalysisWarnings> | ||
|
Comment on lines
-54
to
+55
Member
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. Why? If I trim WinForms app and ask for TrimMode=full, I should get all the warnings. Similarly I would expect this behavior in all other places, basically if I say TrimMode=full - I should get warnings by default (since I asked for the "hard " mode).
Member
Author
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. It's currently blocked off completely, which is why we hide the warnings at all. I think we should either show the warnings or disallow trimming.
Member
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. OK - if we rely on the error for this, then I agree. We should at least add a comment here (why it's OK to suppress). Ideally if the error is disabled we would reenable the warnings (this should really only affect analyzer anyway, the error will trigger before we get to run the linker anyway) |
||
| <!-- Otherwise, for .NET 6+, warnings are on by default --> | ||
| <SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">false</SuppressTrimAnalysisWarnings> | ||
| </PropertyGroup> | ||
|
|
@@ -159,7 +159,7 @@ Copyright (c) .NET Foundation. All rights reserved. | |
| ReferenceAssemblyPaths="@(ReferencePath)" | ||
| RootAssemblyNames="@(TrimmerRootAssembly)" | ||
| TrimMode="$(TrimMode)" | ||
| DefaultAction="$(TrimmerDefaultAction)" | ||
| DefaultAction="$(_TrimmerDefaultAction)" | ||
| RemoveSymbols="$(TrimmerRemoveSymbols)" | ||
| FeatureSettings="@(_TrimmerFeatureSettings)" | ||
| CustomData="@(_TrimmerCustomData)" | ||
|
|
@@ -225,16 +225,23 @@ Copyright (c) .NET Foundation. All rights reserved. | |
| <ILLinkWarningLevel Condition=" '$(ILLinkWarningLevel)' == '' ">0</ILLinkWarningLevel> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Defaults for .NET < 6 --> | ||
| <PropertyGroup Condition=" $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0')) "> | ||
| <TrimMode Condition=" '$(TrimMode)' == '' ">copyused</TrimMode> | ||
| <!-- Action is the same regardless of whether the assembly has an IsTrimmable attribute. (The attribute didn't exist until .NET 6.) --> | ||
| <TrimmerDefaultAction>$(TrimMode)</TrimmerDefaultAction> | ||
| <!-- In .NET 7, TrimmerDefaultAction is deprecated. TrimMode can be used for the supported configurations. --> | ||
| <Warning Condition="'$(TrimmerDefaultAction)' != '' And $([MSBuild]::VersionGreaterThan('$(TargetFrameworkVersion)', '6.0'))" | ||
| Text="Property 'TrimmerDefaultAction' is deprecated in .NET 7 and will be ignored. Use TrimMode instead." /> | ||
|
|
||
| <!-- Set up TrimMode and TrimmerDefaultAction. --> | ||
| <PropertyGroup> | ||
| <TrimMode Condition="'$(TrimMode)' == '' And $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '6.0'))">copyused</TrimMode> | ||
| <TrimMode Condition="'$(TrimMode)' == '' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0'))">partial</TrimMode> | ||
| <TrimMode Condition="'$(TrimMode)' == ''">full</TrimMode> | ||
|
|
||
| <!-- Set TrimmerDefaultAction for compat in < 7.0 --> | ||
| <_TrimmerDefaultAction Condition="$([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '7.0'))">$(TrimmerDefaultAction)</_TrimmerDefaultAction> | ||
| <_TrimmerDefaultAction Condition="'$(_TrimmerDefaultAction)' == '' And $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '6.0'))">$(TrimMode)</_TrimmerDefaultAction> | ||
| <_TrimmerDefaultAction Condition="'$(_TrimmerDefaultAction)' == '' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0'))">copy</_TrimmerDefaultAction> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <TrimMode Condition=" '$(TrimMode)' == '' ">link</TrimMode> | ||
| <!-- 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> | ||
| <TrimmerSingleWarn Condition=" '$(TrimmerSingleWarn)' == '' ">true</TrimmerSingleWarn> | ||
|
|
@@ -295,16 +302,6 @@ Copyright (c) .NET Foundation. All rights reserved. | |
| </ManagedAssemblyToLink> | ||
| </ItemGroup> | ||
|
|
||
| <!-- In .NET6+, set the action explicitly for any with IsTrimmable MSBuild metadata --> | ||
| <ItemGroup Condition=" $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '6.0')) "> | ||
| <ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' == 'true' And '%(ManagedAssemblyToLink.TrimMode)' == '' "> | ||
| <TrimMode>$(TrimMode)</TrimMode> | ||
| </ManagedAssemblyToLink> | ||
| <ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' == 'false' And '%(ManagedAssemblyToLink.TrimMode)' == '' "> | ||
| <TrimMode>$(TrimmerDefaultAction)</TrimMode> | ||
| </ManagedAssemblyToLink> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Don't collapse to a single warning for the intermediate assembly. | ||
| This just sets metadata on the items in ManagedAssemblyToLink that came from IntermediateAssembly. --> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.