Provide a standard item group for OS platforms
See original GitHub issueWe’ve built an analyzer that allows an API to be marked as unsupported for a given set of platforms. We’re going to use this to mark APIs that we can’t make work in Blazor WebAssembly.
In the Blazor case, there are many cuts and they cut deep (threading or file I/O). We don’t want an experience where developers of normal cross-platform class libraries or console apps are confronted with a myriad of diagnostics these APIs don’t work in WebAssembly – most developers don’t need their code to run in those environment.
We intend to address this experience by allowing the developer to include and exclude platforms that the analyzer will consider. Since we want developers to add an remove from the default set, it sees an item group is much more natural fit than a property:
- The base SDK includes a standard set, such as:
<ItemGroup> <SupportedPlatform Include="android" /> <SupportedPlatform Include="ios" /> <SupportedPlatform Include="linux" /> <SupportedPlatform Include="macos" /> <SupportedPlatform Include="windows" /> </ItemGroup>
- The Blazor SDK changes that set:
<ItemGroup> <SupportedPlatform Include="browser" /> </ItemGroup>
- Developers can do this manually in the project file, if, for example, they are building a class library for Blazor:
<ItemGroup> <SupportedPlatform Include="browser" /> </ItemGroup>
- Developers can also manually remove platforms from the project file that they don’t care about:
<ItemGroup> <SupportedPlatform Remove="macos" /> </ItemGroup>
Questions
-
The name seems to conflict with the existing item groups in the SDK has:
SupportedTargetFramework
andSupportedTargetPlatform
. So maybe we should call this oneAnalyzedPlatform
? -
The assumption is that there is a way to pass this to the Roslyn analyzer. @mavasani is looking into that.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Analyzer support is now checked into roslyn-analyzers repo. It uses the item name
SupportedPlatform
- if that is changed, @buyaa-n please rename the field declared at https://github.com/dotnet/roslyn-analyzers/blob/31fe7d4b7dbf85609426f49861ca58f0d2d04b3b/src/Utilities/Compiler/Options/MSBuildItemOptionNames.cs#L21 accordingly.I have a PR out to add this support to NuGet packages built out of analyzers repo: https://github.com/dotnet/roslyn-analyzers/pull/3950
@chsienki just as an FYI,
;
separated list does not work as that is the comment character for editorconfig, so only the first entry gets retained in the analyzer options. I instead used the,
char as separator. @terrajobst to confirm that we don’t expect a,
char in any supported platform name.