c# – 如何让Visual Studio 2015 xproject(project.json)引用依赖项目的最高框架

栏目: C# · 发布时间: 6年前

内容简介:我正在创建一个可重用的库,它针对几个平台(.NET 4.0,.NET 4.5,.NETStandard 1.0和.NETStandard 1.3).此项目的.NET 4.5版本包含.NET 4.0版本下不可用的一些功能.引用此库项目的单元测试项目有一个单一的目标平台,即NET 4.5.1.该测试项目显然包含一些代码,用于测试核心库的.NET 4.5特定功能.不幸的是,测试项目没有编译,因为Visual Studio似乎引用了.NETStandard 1.0版本,显然不包含此功能.

我正在创建一个可重用的库,它针对几个平台(.NET 4.0,.NET 4.5,.NETStandard 1.0和.NETStandard 1.3).此项目的.NET 4.5版本包含.NET 4.0版本下不可用的一些功能.

引用此库项目的单元测试项目有一个单一的目标平台,即NET 4.5.1.该测试项目显然包含一些代码,用于测试核心库的.NET 4.5特定功能.

不幸的是,测试项目没有编译,因为Visual Studio似乎引用了.NETStandard 1.0版本,显然不包含此功能.

为了演示我的问题,我将其简化为以下两个项目:

核心库:

{
  "version": "1.0.0-*",

  "frameworks": {
    "netstandard1.0": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    },
    "net40": {},
    "net45": {}
  }
}

代码文件:

namespace CoreLibrary
{
#if NETSTANDARD1_0
    public class ClassNetStandard { }
#endif

#if NET40
    public class ClassNet40 { }
#endif

#if NET45
    public class ClassNet45 { }
#endif
}

测试库:

{
  "version": "1.0.0-*",

  "dependencies": {
    "CoreLibrary": { "target": "project" }
  },
  "frameworks": {
    "net451": {}
  }
}

码:

// This compiles
new CoreLibrary.ClassNetStandard();

// This doesn't.
// error: Type or namespace 'ClassNet40' does not exist in namespace 'CoreLibrary'
new CoreLibrary.ClassNet40();
// error: Type or namespace 'ClassNet45' does not exist in namespace 'CoreLibrary'
new CoreLibrary.ClassNet45();

我应该更改什么才能让我的单元测试项目编译和测试特定的.NET 4.5功能?


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具