Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect correctly multitargeted apps for trim/AOT/single-file warnings (…
…#35767) The warnings introduced by #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 #35528
- Loading branch information