如何在.Net Framework 4.8中使用.Net Standard 2.1 DLL? [英] How to use a .Net Standard 2.1 DLL in .Net Framework 4.8?

查看:472
本文介绍了如何在.Net Framework 4.8中使用.Net Standard 2.1 DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对.Net Framework 4.8的项目.现在,我们需要使用第三方dll.问题在于该dll是针对.Net Standard 2.1的.

I have a project that is targeted to .Net Framework 4.8. Now, we need to use a 3rd party dll. The problem is that the dll is targeted to .Net Standard 2.1.

是否可以在.Net Framework 4.8项目中使用此dll?

Is there a way to use this dll in the .Net Framework 4.8 project?

我添加了dll,出现此错误:

I added the dll, get this error:

Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

我搜索了一下,似乎应该可以直接使用.也许我需要添加参考?不确定现在需要做什么.

I searched, seems it should work directly. Maybe I need to add a reference? Not sure what needs to do now.

谢谢

推荐答案

否,.NET Framework 4.8不实现.Net Standard 2.1.在 https://docs.microsoft.com/zh-CN/dotnet/standard/net-standard 在框架"下不包含2.1的条目.

No, the .NET Framework 4.8 does not implement .Net Standard 2.1. The .Net Standard .NET implementation support matrix at https://docs.microsoft.com/en-us/dotnet/standard/net-standard does not contain an entry for 2.1 under "Framework".

有关MS决定的更多详细信息: https://devblogs.microsoft.com/dotnet/announcing-net-standard-2-1/

More details on the decision by MS: https://devblogs.microsoft.com/dotnet/announcing-net-standard-2-1/

提取:

鉴于.NET Standard 2.1中的许多API附加要求运行时为了使更改有意义,.NET Framework 4.8将保留在.NET Standard 2.0,而不是实现.NET Standard 2.1..NET核心3.0以及即将发布的Xamarin,Mono和Unity版本将进行更新,以实现.NET Standard 2.1.

Given many of the API additions in .NET Standard 2.1 require runtime changes in order to be meaningful, .NET Framework 4.8 will remain on .NET Standard 2.0 rather than implement .NET Standard 2.1. .NET Core 3.0 as well as upcoming versions of Xamarin, Mono, and Unity will be updated to implement .NET Standard 2.1.

需要支持.NET Framework客户的图书馆作者应继续使用.NET Standard 2.0.实际上,大多数图书馆应该能够保持在.NET Standard 2.0上,因为API的添加主要用于高级方案.但是,这并不意味着图书馆作者即使它们必须支持.NET也无法利用这些API框架.在这种情况下,他们可以使用多目标进行编译.NET Standard 2.0和.NET Standard 2.1.这允许编写可以暴露更多功能或提供更高效率的代码在不支持.NET Standard 2.1的运行时上实现放弃了.NET Standard 2.0提供的更大范围.

Library authors who need to support .NET Framework customers should stay on .NET Standard 2.0. In fact, most libraries should be able to stay on .NET Standard 2.0, as the API additions are largely for advanced scenarios. However, this doesn’t mean that library authors cannot take advantage of these APIs even if they have to support .NET Framework. In those cases they can use multi-targeting to compile for both .NET Standard 2.0 as well as .NET Standard 2.1. This allows writing code that can expose more features or provide a more efficient implementation on runtimes that support .NET Standard 2.1 while not giving up on the bigger reach that .NET Standard 2.0 offers.

简而言之,最简单的方法就是说服第三方支持向后移植/多目标也支持netstandard2.0.或者,您可以切换到.Net Core 3.1(LTS)/Mono,而不是Framework 4.8.

In short, the easiest way would be to convince the 3rd party to backport/multi-target to support netstandard2.0 as well. Or you can switch to .Net Core 3.1 (LTS)/Mono instead of Framework 4.8.

更新:

您还可能会尝试使用.NET Framework兼容模式进行一些欺骗.我不知道你能做到这一点.例如,您可以制作一个包装纸",面向标准并引用您的.Net Framework 4.8代码和第3方库的项目,除非4.8部分使用WPF-也许还有其他陷阱,如下所述.对我来说,这听起来有些令人费解,但是如果您没有其他选择,那么值得一试.在同一原始站点上:

You might also attempt some trickery with .NET Framework compatibility mode. I had no idea you could do this. You could, for example, make a "wrapper" project that targets standard and references both your .Net Framework 4.8 code and the 3rd party library, unless the 4.8 part uses WPF - perhaps there are other pitfalls as stated below. It sounds convoluted to me, but if you have no other options, it might be worth a shot. From the same original site:

从.NET Standard 2.0开始,.NET Framework兼容模式被介绍了.此兼容模式允许.NET Standard(*)项目引用.NET Framework库,就像为它们编译一样.NET标准.引用.NET Framework库不适用于所有项目,例如使用Windows Presentation的库基础(WPF)API.

Starting with .NET Standard 2.0, the .NET Framework compatibility mode was introduced. This compatibility mode allows .NET Standard (*) projects to reference .NET Framework libraries as if they were compiled for .NET Standard. Referencing .NET Framework libraries doesn't work for all projects, such as libraries that use Windows Presentation Foundation (WPF) APIs.

(*)-也是.Net Core(在文档/页面的其他地方)

(*) - Also .Net Core (elsewhere in the document/page)

这篇关于如何在.Net Framework 4.8中使用.Net Standard 2.1 DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆