Search code examples
.net.net-standard.net-standard-2.0

Why can't I use "SupportedOSPlatform" attribute in my .net Standard 2.0 library?


Why can't I use "SupportedOSPlatform" attribute in my .NET Standard 2.0 library?

The compiler doesn't recognize this attribute.

According to docs:

Mark the call as Windows-specific. In some cases, it might make sense to mark the calling member as platform-specific via [SupportedOSPlatform("windows")].


Solution

  • You need .NET 5 for it. See Microsoft docs

    Applies to

    .NET 5.0, 6.0 preview 3

    Related docs: https://learn.microsoft.com/en-us/dotnet/core/compatibility/code-analysis/5.0/ca1416-platform-compatibility-analyzer