我们有一个商业库,我正在努力移植到.NET Core。我想保留其中几个调用,仅在以.NET标准运行时才使用。(出于好奇,一种方法是在Windows服务器上读取一个需要凭据才能访问的文件。)
在那儿:
既然您所描述的,只有一个nuget包并能够根据nuget包所安装的框架来指定不同的行为或依赖项,那么只能通过Multi Targeting来实现。我假设您正在或将要这样做。
一旦指定了目标框架,就可以在预编译块中使用预定义的变量:
#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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句