我创建了一个nuget包,它支持.net框架和.net核心. 但是其中的一个类只有.net核心可用的引用. 我不需要在.net框架中使用该类 是否有任何属性或方法可用,在为.net framweork构建包时排除该类?
但是其中的一个类只有.net核心可用的引用.
我不需要在.net框架中使用该类
是否有任何属性或方法可用,在为.net framweork构建包时排除该类?
这就是我如何定位框架
<TargetFrameworks>netcoreapp2.0;netstandard2.0;net45;net46</TargetFrameworks>只需使用将在每个目标基础上自动提供的条件编译符号.例如:
// Put this at the start of the file (if you want some of the file to still be built)
// or class (if you just want to exclude a single class). You could even
// exclude just a single method, or part of a method.
#if NETCOREAPP2_0 || NETSTANDARD2_0
public class NetFrameworkOnlyClass
{
}
// And this at the end
#endif
或者不包括,你可以这样排除:
#if !NET45 && !NET46
有关每个环境中定义的条件编译符号的列表,请参阅cross-platform library tutorial. (我认为拥有版本中立的“NETCORE”,“NETSTANDARD”和“NETFULL”符号或类似物会很好,但我不相信那些存在.如果你愿意,你可以在项目文件中指定它们.)
