-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Problem statement
The platform compatibility analyzer depends on a set of msbuild items as inputs based on the platform exclusion spec.
From the spec:
In order to indicate which platforms the analyzer should warn about, we're adding some metadata to MSBuild:
<SupportedPlatform Include="..." />
Based on the spec, the SupportedPlatform item defines the list of platforms that the platform compatibility analyzer should warn about.
The SDK unconditionally adds supported platforms and one of those is Windows. The SDK itself doesn't make it possible to only target platforms like macOS or Linux via a target platform, but we in dotnet/runtime allow that via the Microsoft.DotNet.TargetFramework.Sdk.
As reported in #69980 (comment), the warnings are currently not correct in certain cases, i.e. when a target framework is platform agnostic.
Here you can see that the SupportedPlatform metadata is added for Browser when the platform is Browser, or when it's agnostic and the library doesn't have a Browser specific implementation.
I think we would want the same for Unix and for any other platform.
Possible solution
Please see ViktorHofer#2 (my fork, just to get feedback). That logic calculates the SupportedPlatforms items correctly based on the RID graph. This implementation is completely static but solves the noted issues.
To make this dynamic, an msbuild task in the TargetFramework.Sdk would be required that takes the build rid graph (OSGroups.json), TargetFrameworks, TargetFramework and TargetPlatformIdentifier as an input and outputs the SupportedPlatform item to be added.