Skip to content

Commit 1044563

Browse files
committed
Detect correctly multitargeted apps for trim/AOT/single-file warnings (dotnet#35767)
The warnings introduced by dotnet#34077 and described in https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/trimming-unsupported-targetframework are unnecessary noise for projects that multitarget to include a TargetFramework that is compatible with trimming/AOT/single-file, and is a low enough version to ensure that it will be picked over any other TFM's assets when the library is consumed in a trimmed/AOT'd/single-file app. This fixes the issue by detecting correctly multi-targeted libraries and suppressing the warnings in these cases. Note that prior to the .NET 8 SDK, netstandard libraries would still get the `IsTrimmable` attribute embedded in the assembly when setting `IsTrimmable`, and could use trim analysis despite incomplete warnings due to unannotated ref assemblies. With the .NET 8 SDK this is no longer the case. Even for correctly multi-targeted libraries, the netstandard output assembly will no longer contain the `IsTrimmable` attribute. We debated whether it was worth warning in this case, but decided that the negative impact of the warning on library developers following the "golden path" was too large to justify keeping this as a warning. This solution addresses a correctness problem that we wanted to avoid (the correctness problem: allowing an inadvertently non-"trimmable" netstandard asset to be consumed in a trimmed app that uses a supported TFM). It's still possible to get into that situation in an app that explicitly references the netstandard assembly, or that targets an EOL TFM (causing it to consume the netstandard asset from a library that multitargets `netstandard2.0;net6.0` for example). Fixes dotnet#35528
1 parent bfcdc76 commit 1044563

22 files changed

+330
-177
lines changed

src/Tasks/Common/Resources/Strings.resx

+3-3
Original file line numberDiff line numberDiff line change
@@ -931,17 +931,17 @@ You may need to build the project on another operating system or architecture, o
931931
</data>
932932
<data name="IsAotCompatibleUnsupported" xml:space="preserve">
933933
<value>NETSDK1210: IsAotCompatible is not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:
934-
&lt;IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))"&gt;true&lt;/IsAotCompatible&gt;</value>
934+
&lt;IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '{0}'))"&gt;true&lt;/IsAotCompatible&gt;</value>
935935
<comment>{StrBegin="NETSDK1210: "}</comment>
936936
</data>
937937
<data name="EnableSingleFileAnalyzerUnsupported" xml:space="preserve">
938938
<value>NETSDK1211: EnableSingleFileAnalyzer is not supported for the target framework. Consider multi-targeting to a supported framework to enable single-file analysis, and set EnableSingleFileAnalyzer only for the supported frameworks. For example:
939-
&lt;EnableSingleFileAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))"&gt;true&lt;/EnableSingleFileAnalyzer&gt;</value>
939+
&lt;EnableSingleFileAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '{0}'))"&gt;true&lt;/EnableSingleFileAnalyzer&gt;</value>
940940
<comment>{StrBegin="NETSDK1211: "}</comment>
941941
</data>
942942
<data name="IsTrimmableUnsupported" xml:space="preserve">
943943
<value>NETSDK1212: IsTrimmable is not supported for the target framework. Consider multi-targeting to a supported framework to enable trimming, and set IsTrimmable only for the supported frameworks. For example:
944-
&lt;IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))"&gt;true&lt;/IsTrimmable&gt;</value>
944+
&lt;IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '{0}'))"&gt;true&lt;/IsTrimmable&gt;</value>
945945
<comment>{StrBegin="NETSDK1212: "}</comment>
946946
</data>
947947
<data name="Net8NotCompatibleWithDev177" xml:space="preserve">

src/Tasks/Common/Resources/xlf/Strings.cs.xlf

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tasks/Common/Resources/xlf/Strings.de.xlf

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tasks/Common/Resources/xlf/Strings.es.xlf

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)