且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Windows窗体移植到.Net Standard 2.0

更新时间:2023-12-06 09:08:52

您不能构建针对.NET Standard 2.0的应用程序.只有库可以针对.NET Standard.应用程序仍然必须针对特定的运行时-.NET Framework,.NET Core,Xamarin等.

You cannot build an application that targets .NET Standard 2.0. Only libraries can target .NET Standard. Applications still have to target a specific runtime - .NET Framework, .NET Core, Xamarin, etc.

从您的项目文件来看,您实际上是在瞄准.NET Core 2.0.

Judging by your project file, you're actually targeting .NET Core 2.0.

System.Windows.Forms是.NET Framework(和Mono)的一部分.它不作为.NET Standard或.NET Core的一部分存在.

System.Windows.Forms is part of the .NET Framework (and Mono). It does not exist as part of .NET Standard or .NET Core.

您的项目文件的System.Windows.Forms具有PackageReference,它将拉入

Your project file has a PackageReference to System.Windows.Forms, which will pull in this NuGet package. It's unofficial and unlisted. It's very description is "unsupported library".

该程序包中的DLL只是一个参考程序集,即所有方法均不包含任何实际代码.该程序集仅包含定义.

The DLL inside that package is only a reference assembly, i.e. none of the methods contain any actual code. That assembly only contains definitions.

这是错误消息表示不应加载参考程序集以执行"的意思.该程序包中的程序集将允许您进行编译,但是没有其他内容.

This is what the error message means by "Reference assemblies should not be loaded for execution." The assembly in that package will let you compile, but nothing else.

没有正式的方法可以在.NET Core(3.0之前的版本)上运行Windows Forms应用程序.将我们的业务逻辑放入.NET Standard程序集中可能会有好处,但是您的用户界面仍然必须是.NET Framework应用程序.

There is no formal way to run a Windows Forms application on .NET Core (prior to 3.0). There may be benefit to pulling our your business logic into a .NET Standard assembly, but your user interface will still have to be a .NET Framework application.