需要帮助将 winform 迁移到 net 5

need help migrating winform to net 5

我正在将 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.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" >

我不明白这个错误,错误发送给我的 link 没有帮助

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