为什么我不能在 .net Standard 2.0 库中使用 "SupportedOSPlatform" 属性?

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

为什么我不能在我的 .NET Standard 2.0 库中使用“SupportedOSPlatform”属性?

编译器无法识别此属性。

根据文档:

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

您需要 .NET 5。参见 Microsoft docs

Applies to

.NET 5.0, 6.0 preview 3

相关文档:https://docs.microsoft.com/en-us/dotnet/core/compatibility/code-analysis/5.0/ca1416-platform-compatibility-analyzer