简体   繁体   English

在.net核心和.net框架中使用.net标准包

[英]Using a .net standard package in .net core and .net framework

I have a package that is built using .net Standard 2.0. 我有一个使用.net Standard 2.0构建的包。 I want to be able to utilise it in both .net Framework and .net Core applications but it has the following line of code: 我希望能够在.net Framework和.net Core应用程序中使用它,但它具有以下代码行:

using System.Runtime.Loader;

…

AssemblyLoadContext.Default.Unloading += (ctx) => ProcessStop();
…

This doesn't work for the .net Framework (seems like the System.Runtime.Loader is a core only package). 这不适用于.net Framework(看起来像System.Runtime.Loader是一个核心包)。 I can omit it at compile time using this sort of statement: 我可以在编译时使用这种语句省略它:

#if NETCOREAPP2_0 || NETCOREAPP2_1
            AssemblyLoadContext.Default.Unloading += (ctx) => ProcessStop();
#endif

Which doesn't help me when the package is compiled already and I want to use it in .net Framework. 在编译软件包时,这对我没有帮助,我想在.net Framework中使用它。 Anyone know how to do this sort of thing inline? 有人知道怎么做内联这种东西吗?

Thanks for any pointers in advance! 在此先感谢您的任何指示!

It seems that there is an issue with AssemblyLoadContext (or the System.Runtime.Loader package to be precise) according to https://github.com/dotnet/cli/issues/6019 The package claims to support .NET-Framework (and netstandard1.5) but apparently doesn't. 似乎存在具有问题AssemblyLoadContext根据(或System.Runtime.Loader包要准确) https://github.com/dotnet/cli/issues/6019封装声称支持.NET的框架(和netstandard1.5)但显然没有。 So yes, System.Runtime.Loader seems to be a core-only package - what absolutely perverts the concept of .NET-Standard in my opinion... 所以,是的,System.Runtime.Loader似乎是一个仅核心的软件包 - 在我看来,绝对颠覆了.NET-Standard的概念......

The consequence of this now is, that the .NET-Standard 2.0 package you mentioned does not really support .NET-Standard 2.0, but .NET-Core >= 1.0 (from the System.Runtime.Loader point of view). 现在的结果是,您提到的.NET-Standard 2.0软件包并不真正支持.NET-Standard 2.0,但.NET-Core> = 1.0(从System.Runtime.Loader的角度来看)。 I don't see any chance to make an already compiled version without that mentioned switch work with .NET-Framework. 如果没有提到的开关与.NET-Framework一起使用,我认为没有机会制作已编译的版本。

Anyone know how to do this sort of thing inline? 有人知道怎么做内联这种东西吗?

When providing the mentioned library as NuGet-package, there is the posibility to extract runtime-specific implementations to runtime-specific DLLs: https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks But this, of course, implies recompiling the package. 将提到的库作为NuGet-package提供时,可以将运行时特定的实现提取到特定于运行时的DLL: https//docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple- target-frameworks但是,这当然意味着重新编译包。

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

相关问题 .net 标准库在 .net 核心中失败,但在框架中失败 - .net standard library fails in .net core but not in framework 减少.net核心/标准中的程序包依赖性 - Reducing Package Dependencies in .net core/standard 在带有.NET Core(.NET Standard 1.4和.NET Framework 4.6.1)的System.Net.Http中使用await / async时出现错误? - Bug when using await/async for System.Net.Http with .NET Core (.NET Standard 1.4 and .NET Framework 4.6.1)? 在.NET Core Web API中安装自定义.NET Standard NuGet软件包 - Install custom .NET Standard NuGet Package in .NET Core Web API 如何将 .Net Standard Nuget 包添加到 .Net 4.5 Framework 项目中? - How to add .Net Standard Nuget package into .Net 4.5 Framework Project? 如何在 Visual Studio 中将 .NET Framework 更改为 .NET Standard/Core? - How to change .NET Framework to .NET Standard/Core in Visual Studio? 在 .Net 核心和 .Net 标准身份框架之间共享通用数据库 - Sharing common database between .Net core and .Net standard Identity framework .NET 标准、.NET 核心、PCL - .NET Standard, .NET Core, PCL 净标准包装 - Net standard package 针对.net核心和.net框架4.6的Nuget包兼容性 - Nuget package compatibility for .net core and .net framework 4.6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM