有没有办法在.NET Core库中包含.NET Framework代码? [英] Is there a way to have .NET Framework code in a .NET Core library?
问题描述
我们有一个商业库,我正在努力移植到.NET Core.我想保留其中几个调用,仅在以.NET标准运行时才使用.(出于好奇,一种方法是在Windows服务器上读取一个需要凭据才能访问的文件.)
We have a commercial library that I am working to port to .NET Core. There are a couple of calls in it I want to retain to use only if running in .NET standard. (For the curious, one set is to read a file on a Windows server that requires credentials to access.)
在那里:
- 一个电话,它将告诉我是否在.NET Standard与.NET Core之间运行.
- 是否有一种方法可以使类仅在标准情况下运行才能实例化/调用,但DLL在Core下仍可以正常加载?
推荐答案
根据您的描述,只有单个nuget程序包并能够根据nuget程序包所安装的框架指定不同的行为或依赖项,通过多目标假设您正在这样做或将要这样做. Since what you describe, having a single nuget package and being able to specify different behaviours or dependencies depending on the framework the nuget package is installed into, can only be reached through Multi Targeting I will assume you are doing that or will be doing it. 一旦您拥有指定的目标框架,您可以在预编译块中使用预定义的变量: Once you have specified target frameworks, you have pre-defined variables to use in precompile blocks: 这篇关于有没有办法在.NET Core库中包含.NET Framework代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!#if NETFRAMEWORK
// use full framework class here. You were installed into a full framework app or library
#elif NETCOREAPP
// use .NET Core class here. You were installed into a .NET Core app or library
#else NETSTANDARD
// uh... okay... you were installed into another .NET Standard library,
// we still have no idea where *that* might be installed... help?
// Maybe make it configurable after all?
#endif