我有一个使用 .NET 8 构建并面向 Windows 平台的 ASP.NET Core 应用程序(实现 REST API)(需要面向 Windows,因为它使用需要 Windows 的
System.DirectoryServices
)。该应用程序不显式或隐式使用 Windows 窗体(没有包依赖于 Windows 窗体)。但由于某种原因,它仍然需要 System.Windows.Forms
和 System.Windows.Forms.Primitives
。我将 UseWindowsForms
设置添加到项目文件中,但没有帮助:
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>false</UseWindowsForms>
有没有办法让为 Windows 平台构建的 .NET Core 应用程序不需要 Windows 窗体?如果重要的话,我正在使用 Visual Studio 2022。
根据 https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4468,这是
Microsoft.Identity.Client
包的更高版本中引入的错误。有几种解决方法可以使用。我选择将 Windows
操作系统设置更改回 (None)
并通过 CA1416
文件中的以下行禁用 .editorconfig
警告:
dotnet_diagnostic.CA1416.severity = none
警告只是说
System.DirectoryServices
API仅适用于Windows,但只要应用程序部署在Windows系统上,就可以了。