我正在将一个 winform 应用程序从 net core 3.1 移植到 net 5 并收到以下错误。
Severity Code Description Project File Line Suppression State Error NETSDK1136 The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so. PublicOutput.core C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 369
这是所指的 Microsofts.net.sdk.DefaultItems.targets 部分。
<Target Name="_CheckForInvalidWindowsDesktopTargetingConfiguration"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '5.0')) and ('$(UseWindowsForms)' == 'true' or '$(UseWPF)' == 'true')">
<NETSdkError Condition="'$(TargetPlatformIdentifier)' != 'Windows'"
ResourceName="WindowsDesktopTargetPlatformMustBeWindows" >
我不明白错误,错误发送给我的链接没有帮助https://docs.microsoft.com/en-us/visualstudio/?f1url=%3FappId%3DDev16IDEF1%26l%3DEN-US%26k%3Dk(NETSDK1136)%26rd%3Dtrue&view=vs-2019
我的目标框架设置如下:
<TargetFramework>net5.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
任何帮助,将不胜感激
最佳答案
错误很明显:
The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF,
所以改变
<TargetFramework>net5.0</TargetFramework>
至 <TargetFramework>net5.0-windows</TargetFramework>
如 written in docs
关于c# - 需要帮助将 winform 迁移到 net 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64786573/