c# - 需要帮助将 winform 迁移到 net 5

标签 c# winforms .net-core migration .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\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/

相关文章:

c# - 跳过 HttpResponseMessage Content.ReadAsStream 的第一行(CSV 标题行)

c# - 无法从 Visual Studio C# 连接到数据库

C#/ODP.NET : large IN clause workaround

c# - 在 C# 中将 Action 委托(delegate)作为参数传递

c# - 如何使用ComboBox的SelectedIndexChanged-Event

c# - 防止加载 DataGridView RowEnter 事件

在 Visual Studio Code 中调试 MSTest 单元测试

c# - 嵌套成员的 ArgumentNullException

multithreading - 在XP上长时间运行时,vb6应用程序挂起

c++ - CoreCLR 中的 Instrumentation Profiler - 将 HelperAssembly 加载到 dotnet 进程的方法