简体   繁体   English

将项目从 .NET5 转换为 .NET Framework 4.8

[英]Converting a project from .NET5 to .NET Framework 4.8

Long story, summarized... I started working on a solution creating many projects (like class libraries) for the solution.长话短说,总结......我开始研究一个解决方案,为该解决方案创建许多项目(如 class 库)。 Then I ended up needing to use a third-party SDK for something I had an expensive license for.然后我最终需要使用第三方 SDK 来购买我拥有昂贵许可证的东西。 Come to find out, that third-party SDK only supported .NET Framework .来了解一下,第三方 SDK 只支持.NET Framework

Because my solution was based in .NET 5/Core and the SDK in .NET Framework I had a big issue.因为我的解决方案基于.NET 5/Core.NET Framework中的 SDK,所以我遇到了一个大问题。 They can not exist in the same environment and reference each other.它们不能存在于同一环境中并相互引用。 So, on to biting the bullet and spending hours converting all my projects to .NET Framework 4.8 while singing a neverending song of curse words...因此,继续咬紧牙关,花费数小时将我所有的项目转换为.NET Framework 4.8 ,同时唱着永无止境的诅咒之歌……

The Issue问题

My first class library I'm trying to convert from .NET5 to .NET 4.8 happens to have a Nuget package installed.我的第一个 class 库我正在尝试从.NET5转换为.NET 4.8碰巧安装了 Nuget ZEFE470A8E6034AZF7C8C8。 That Nuget is Newtonsoft.Json Version="12.0.3" ( https://www.nuget.org/packages/Newtonsoft.Json ). That Nuget is Newtonsoft.Json Version="12.0.3" ( https://www.nuget.org/packages/Newtonsoft.Json ).

After changing the framework in the project file, VSCode is telling me the Newtonsoft namespace can not be found.在项目文件中更改框架后,VSCode 告诉我找不到 Newtonsoft 命名空间。 This makes me think that the Nuget I have installed is not compatible with .NET Framework 4.8.这让我觉得我安装的 Nuget 与 .NET Framework 4.8 不兼容。

The issue I was running into was the namespace Newtonsoft could not be found after changing the framework from net5.0 to net48 .我遇到的问题是将框架从net5.0更改为net48后找不到命名空间Newtonsoft

The issue was OmniSharp that was giving a false positive.问题是 OmniSharp 给出了误报。 I restarted VSCode and the issue went away once VSCode loaded with the new framework being used.我重新启动了 VSCode,一旦 VSCode 加载了正在使用的新框架,问题就消失了。

.NET supports cross platform targeting which means you can have your SDK style .NET5 project multi-targets both net5 and net48 . .NET 支持跨平台定位,这意味着您可以让您的 SDK 风格的 .NET5 项目同时定位net5net48 In future, if the third-party library targets .NET Core then you can simply change the TargetFrameworks property.将来,如果第三方库以.NET Core为目标,那么您只需更改TargetFrameworks属性即可。

A similar issue has been discussed here https://github.com/dotnet/runtime/discussions/40304 incase if that helps.如果有帮助,这里已经讨论了一个类似的问题https://github.com/dotnet/runtime/discussions/40304

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM