简体   繁体   English

我可以从 .NET 5 项目中添加对 .NET Framework DLL 的引用吗?

[英]Can I add a reference to a .NET Framework DLL from a .NET 5 project?

Microsoft recently announced at Build 2019 that the next major version of .NET will unify both .NET Core 3.* and .NET Framework 4.* into a single .NET platform, which the major version number will be 5.微软最近在 Build 2019 上宣布,.NET 的下一个主要版本将把 .NET Core 3.* 和 .NET Framework 4.* 统一到一个单一的 .NET 平台中,主要版本号为 5。

I didn't understand it well, does it mean that using .NET 5 I will be able to add references to libraries written in both version of .NET?我不太明白,这是否意味着使用 .NET 5 我将能够添加对用 .NET 的两个版本编写的库的引用?

For example, a .NET 5 project referencing 2 assemblies, one that was compiled targeting .NET Core 3 and another compiled targeting .NET Framework 4.5 (in this case, as it references a .NET Framework library, I think it would only be able to run on Windows).例如,一个 .NET 5 项目引用了 2 个程序集,一个是针对 .NET Core 3 编译的,另一个是针对 .NET Framework 4.5 编译的(在这种情况下,因为它引用了 .NET Framework 库,我认为它只能在 Windows 上运行)。

.NET 5 will have the same compatilbity layer that .NET Core currently has. .NET 5 将具有与 .NET Core 当前相同的兼容性层。

This allows you to reference .NET Framework DLLs with the caveat that the DLL may not load or execute at runtime.这允许您引用 .NET Framework DLL,但注意 DLL 可能不会在运行时加载或执行。 If it is a logic library, it may work well.如果它是一个逻辑库,它可能工作得很好。 Not su much if it relieves on eg System.Web .如果它在例如System.Web上减轻,则不会那么多。 This is especially useful for 3rd party libraries which you don't have the source code for.这对于您没有源代码的 3rd 方库特别有用。 You can use the The .NET Portability Analyzer to check for any use of unsupported APIs in such libraries.您可以使用.NET Portability Analyzer检查此类库中是否使用了不受支持的 API。

That being said, you should try to change your existing .NET Framework libraries to .NET Standard or multi-target to bot .NET Framework and .NET Standard.也就是说,您应该尝试将现有的 .NET Framework 库更改为 .NET Standard 或将多目标更改为 bot .NET Framework 和 .NET Standard。

It will be the same as today: you will be able to reference .NET Standard libraries.它将与今天相同:您将能够引用 .NET Standard 库。 .NET 5 does not contain everything of the classic framework, therefore it won't be possible to reference a .NET 4.x assembly directly. .NET 5 不包含经典框架的所有内容,因此无法直接引用 .NET 4.x 程序集。 Therefore start to write libraries in .NET Standard.因此开始在 .NET Standard 中编写库。

However in .NET Core 2.0 Microsoft implemented the compatibility shim that allows type forwarding of missing tpyes in old assemblies to the new type.但是,在 .NET Core 2.0 中,Microsoft 实现了兼容性填充,允许将旧程序集中缺少的类型转发到新类型。 As long as your library does not use any classes that are not supported by .NET 5, you're safe.只要您的库不使用 .NET 5 不支持的任何类,您就是安全的。

See this post or this for more information.看到这个职位了解更多信息。

This is a great question and one that I've spent a fair amount of time trying to answer for myself.这是一个很好的问题,我花了很多时间试图为自己回答。 One thing that really helped me was to realize that .NET 5.0 is really just the next version of .NET Core.真正帮助我的一件事是意识到 .NET 5.0 实际上只是 .NET Core 的下一个版本。

This video at the 24:30 mark really makes this point well: https://youtu.be/4WJHCvwE2VM?t=1470这个 24:30 标记的视频确实很好地说明了这一点: https ://youtu.be/4WJHCvwE2VM?t =1470

With that in mind we can see that things will continue to work as they do in .NET Core 2.0 and earlier where if you want to make use of classic .NET Framework code, then you must first move that code into a .NET Standard class library.考虑到这一点,我们可以看到事情将继续像在 .NET Core 2.0 及更早版本中那样工作,如果您想使用经典的 .NET Framework 代码,那么您必须首先将该代码移动到 .NET Standard 类中图书馆。

Since.Net don't have all functionalities as .net classic did.因为 .Net 不像 .net classic 那样具有所有功能。 You can any DLL from classic to a newer version, infant I've also used libraries from VB in C# and vice versa.您可以使用从经典版本到较新版本的任何 DLL,婴儿我也在 C# 中使用过 VB 中的库,反之亦然。

There is one problem though, as long as libraries don't call any unsupported API or APIs that have ended support or have been closed will be a problem.但是有一个问题,只要库不调用任何不受支持的 API 或已结束支持或已关闭的 API,就会出现问题。

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

相关问题 在 .Net 5 项目中引用兼容的 .Net 框架 dll 但我得到一个例外 - Reference compatible .Net framework dll in .Net 5 project but I get an exception 在Full Framework 4.7项目上添加对.NET Core 2.0 DLL的引用 - Add reference to a .NET Core 2.0 DLL on a Full Framework 4.7 project 从 .Net Framework 项目添加对 .Net Core 项目的引用 - Add a reference to .Net Core project from .Net Framework project 无法添加项目.net core 2参考,但可以添加dll .net core 2参考 - Can't add a project .net core 2 reference but can add a dll .net core 2 reference 如何将.NET dll引用添加到UWP项目? - How to add .NET dll reference to UWP project? 我可以从.NET 4.0项目引用.NET 4.5项目吗? - Can I reference a .NET 4.5 project from a .NET 4.0 project? 完整.NET Framework上ASP.NET Core项目内的NuGet文件夹中的参考DLL - Reference DLL from NuGet folder inside ASP.NET Core project on full .NET framework 我可以在普通的.NET Framework应用程序中安全地引用NETMF项目吗? - Can I safely reference a NETMF project in a normal .NET Framework app? 将参考.NET Framework项目添加到.NET Core项目 - Add reference .NET Framework project to .NET Core project 如何在 .NET Core 项目中引用 .NET Framework 项目? - How do I reference a .NET Framework project in a .NET Core project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM