加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – .net核心和.net框架4.6的Nuget包兼容性

发布时间:2020-12-16 01:26:25 所属栏目:百科 来源:网络整理
导读:我创建了一个nuget包,它支持.net框架和.net核心. 但是其中的一个类只有.net核心可用的引用. 我不需要在.net框架中使用该类 是否有任何属性或方法可用,在为.net framweork构建包时排除该类? 这就是我如何定位框架 TargetFrameworksnetcoreapp2.0;netstandard
我创建了一个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

有关每个环境中定义的条件编译符号的列表,请参阅cross-platform library tutorial. (我认为拥有版本中立的“NETCORE”,“NETSTANDARD”和“NETFULL”符号或类似物会很好,但我不相信那些存在.如果你愿意,你可以在项目文件中指定它们.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读