繁体   English   中英

针对.net核心和.net框架4.6的Nuget包兼容性

[英]Nuget package compatibility for .net core and .net framework 4.6

我创建了一个nuget包,它支持.net框架和.net核心。 但是其中的一个类只有.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

请参阅跨平台库教程 ,以获取在每个环境中定义的条件编译符号的列表。 (我认为这将是不错的版本中性“ NETCORE ”,“ NETSTANDARD ”和“ NETFULL ”符号或类似的,但我不相信那些存在,你可以在你的项目文件中指定他们,如果你想。)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM