动态加载的程序集的兼容性 [英] Compatibility of dynamically loaded assemblies

查看:65
本文介绍了动态加载的程序集的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时动态加载dotnet程序集。



假设我有netcore 3.1控制台应用程序:




  • 我可以加载吗?净标准组件?如果可以,我可以加载哪个特定版本?

  • 是否可以加载经典的.net程序集,例如.net framework 4.8?如果可以,我还可以加载旧版本吗?



当我拥有dotnet framework 4.8控制台应用程序时,反向情况如何:




  • 我可以加载.net标准程序集吗?

  • 我可以加载旧的经典.net吗?框架4.6?


解决方案

.NET Standard是接口-可以调用的API版本列表。



.NET框架和.NET核心都可以引用.Net标准。


这是什么意思?


您应该对类库使用.Net标准。



.NET框架和.NET核心这两个目标平台。
.Net框架仅可在Windows上运行,而.Net核心可在所有三个(Windows / Linux / MacOS)操作系统上运行。 这些不应相互引用。


这就是为什么存在.Net标准的原因。


因此,可以快速回答您的问题。




  • 我可以加载.net标准程序集吗?如果可以,我可以加载哪个特定版本? 是的,您应该使用.Net标准

  • 我可以加载经典的.net程序集,例如.net framework 4.8吗?如果可以,我还可以加载旧版本吗? 您肯定可以肯定



当我拥有dotnet framework 4.8时,逆向情况如何?控制台应用程序:




  • 我可以加载.net标准程序集吗? 是的!

  • 我可以加载较旧的经典.net,例如程序集,.net Framework 4.6吗?是的!但是,请在这里好好看看->


    为了避免定位错误传递依赖项错误或至少将其保持在最低水平。使用.NET标准时,将软件包管理更改为 PackageReference


    < RestoreProjectStyle> PackageReference< / RestoreProjectStyle>



    下面的链接提供了完整的信息以及一些针对此类错误的故障排除提示。



    来源: https://www.hanselman.com/ Blog / ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx


    I want to dynamically load dotnet assemblies at runtime.

    Let's say I have netcore 3.1 console app:

    • Can I load .net standard assemblies? If yes what specific version I can load?
    • Can I load classic .net assemblies, like .net framework 4.8? If yes can I also load older versions?

    What about reverse situation, when I have dotnet framework 4.8 console app:

    • Can I load .net standard assemblies?
    • Can I load older classic .net, like assemblies,.net framework 4.6?

    解决方案

    .NET Standard is an interface - a versioned list of APIs that you can call.

    .Net standard can be referenced by both .NET framework and .NET core.

    What does this mean?

    You should use .Net standard for class libraries.

    .NET framework and .NET core those two target a platform. .Net framework only works on Windows while .Net core works on all three(Windows/Linux/MacOS) operating systems. These should not reference one another.

    This is why .Net standard exists.

    So to quickly answer your questions.

    • Can I load .net standard assemblies? If yes what specific version I can load? Yes, you should use .Net standard
    • Can I load classic .net assemblies, like .net framework 4.8? If yes can I also load older versions? You probably can, for sure you should not

    What about reverse situation, when I have dotnet framework 4.8 console app:

    This is for .NET Standard. Taken from Microsoft Docs.

    The documentation is very clear on what you need to pay attention to. The text below is similar to the one in the screenshot. I added here to be more readable.

    The following table lists the minimum platform versions that support each .NET Standard version. That means that later versions of a listed platform also support the corresponding .NET Standard version. For example, .NET Core 2.2 supports .NET Standard 2.0 and earlier.

    Guide

    In addition to this ->https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support

    In order to avoid targeting errors and transitive dependencies errors or at least keep them to a minimum. Change your package management to PackageReference when using .NET standard.

    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>

    The link below provides the full info and also some troubleshooting tips for such errors.

    Source: https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx

    这篇关于动态加载的程序集的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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