.NET SupportedOSPlatformAttribute: what values my I validly use?
Asked Answered
R

2

7

I've got this attribute in an AssemblyInfo file. Right now it's set to this:

System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]

As per the docs, the idea at the time was to keep anyone from trying to use the software on anything earlier than windows 7

But I have no memory of where I got the actual literal string "windows7.0". Is there some documented list of valid platforms to use? Do I just say, "windows8.0" for windows 8? "windows10.0" for windows 10? etc? The Microsoft documentation does not seem to give any guidance

Rift answered 29/9, 2022 at 20:25 Comment(0)
G
1

In this case it's not just a platform but platform version which seems to be build as simple string concatenation. There are multiple examples in the platform compatibility analyzer article in the docs.

Also AFAIK you should be able to use RIDs (Runtime Identifiers) for this, see more at the docs and in the github repo.

Also OS-specific TFMs (target framework moniker) doc can be useful.

Gagarin answered 29/9, 2022 at 21:5 Comment(0)
W
1

Microsoft's CA1418: Validate platform compatibility code analyzer rule can also help. It primarily uses the OperatingSystem class's Is<PlatformName>[VersionAtLeast]() methods to infer the set of valid platform names. But it also supports a customizable list of supported platforms, and it has logic to determine when versions are allowed.

The known platform names list is populated from two places:

  • The PlatformName part of OperatingSystem guard methods named OperatingSystem.Is<PlatformName>[VersionAtLeast](). For example, guard method OperatingSystem.IsWindows() adds Windows to the known platform names list.

  • The project's MSBuild item group of SupportedPlatform items, including the default MSBuild SupportedPlatforms list. This is the project specific knowledge of known platforms. It allows class library authors to add more platforms into the known platforms list. For example:

<ItemGroup>
    <SupportedPlatform Include="PlatformName" />
</ItemGroup> 

If the platform string contains a version part, it should be a valid Version with the following format: major.minor[.build[.revision]].

Wordplay answered 28/8, 2024 at 14:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.