Compatibility of dynamically loaded assemblies

后端 未结 1 1208
情话喂你
情话喂你 2020-11-30 14:53

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 s
相关标签:
1条回答
  • 2020-11-30 15:11

    .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:

    • Can I load .net standard assemblies? Yes!
    • Can I load older classic .net, like assemblies,.net framework 4.6? Yes! But, take a good look here -> https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/version-compatibility#Apps

    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

    0 讨论(0)
提交回复
热议问题