CA1416。如何告诉构建者唯一的平台是Windows?

2024-01-02

dotnet run(在 Windows 上)原因warning CA1416: This call site is reachable on all platforms. 'WellKnownSidType.WorldSid' is only supported on: 'windows'.

我的程序设计为仅在 Windows 上运行。

我尝试添加SupportedPlatform to MyApp.csproj,但没有运气。

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="5.0.5" />
    <PackageReference Include="System.DirectoryServices" Version="5.0.0" />
    <SupportedPlatform Include="Windows"/>
  </ItemGroup>

</Project>

我究竟做错了什么?我怎样才能展示dotnet run该项目仅适用于 Windows?


您可以使用以下标记标记每个特定于 Windows 的方法System.Runtime.Versioning.SupportedOSPlatformAttribute e.g.

[SupportedOSPlatform("windows")]
public static void Foo()
    => Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

在 AssemblyInfo 中标记整个程序集(如果有)

[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]

Or edit .csproj文件以针对特定于 Windows 的 dotnet 版本,以使这些更改自动进行

<TargetFramework>net5.0-windows</TargetFramework>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CA1416。如何告诉构建者唯一的平台是Windows? 的相关文章

随机推荐