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

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

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

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

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

核心库:

{ "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(); 

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

.NET Core的Visual Studio工具中似乎存在一个错误。 当您从另一个引用多框架项目时 – Visual Studio仅从列表中获取第一个列出的框架(在您的情况下 – “netstandard1.0”),并将该引用的项目视为此框架的单个目标。 但是,编译器正确处理这个问题,虽然项目似乎正确构建 – 实际上它没有。 另一方面,当你使用ClassNet45定义时 – 似乎它没有编译(Visual Studio显示错误) – 它确实编译成功。

似乎用于.NET Core的Visual Studio工具尚未完善,但可能这个错误将在不久的将来得到解决。