无法获得.NET Core NUnit测试项目对我的生产类库的引用

时间:2016-09-16 18:09:32

标签: c# nunit .net-core nunit-3.0

我可以为生产装配和单元测试装配提供最简单的解决方案设置。首先,这是相关的配置:

Common.sln
global.json
-- src
---- Common
------ project.json
-- test
---- UnitTests
------ project.json

global.json

{
  "projects: [ "src", "test" ]
}

Common\project.json

{
  "name": "<redacted>",
  "version": "2.0.0-*",
  "description": "<redacted>",
  "copyright": "© 2016 <redacted>",
  "title": "<redacted>",
  "authors": [ "<redacted>" ],
  "language": "en-US",
  "buildOptions": {
    "platform": "anycpu",
    "xmlDoc": true
  },
  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

UnitTests\project.json

{
  "version": "0.0.0-*",
  "testRunner": "nunit",
  "dependencies": {
    "Common": {
      "target": "project"
    },
    "NUnit": "3.4.1",
    "dotnet-test-nunit": "3.4.0-beta-2"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "netcoreapp1.0",
        "portable-net45+win8"
      ],
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1-*",
          "type": "platform"
        }
      }
    }
  }
}

当我编译时,我在错误列表中得到这些错误:

Error   NU1002  The dependency Common  does not support framework .NETCoreApp,Version=v1.0. UnitTests   <redacted>\UnitTests\project.json   5   
Error           The given key was not present in the dictionary.    UnitTests       1   

这里发生了什么?我已经按照我可以找到的每个教程来尝试设置这些项目,但它们都不起作用。自创建教程以来,.NET Core中的内容可能已经发生了变化?我需要更改什么才能让UnitTests项目识别我的Common项目?

另外两个较小的问题:

  1. 我正在运行Windows 7 SP1。这是否会导致portable-net45+win8导入问题?
  2. 有一个更新版本的Microsoft.NETCore.App:1.0.1。最初,project.json引用了1.0.0版本,因此我对其进行了更改。但是,在Solution Explorer中,我仍然看到1.0.0。
  3. 参考文献:

    http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/

1 个答案:

答案 0 :(得分:0)

事实证明,我所看到的几乎所有内容都只是工具问题。我希望微软尽快解决这个问题。在错误列表中看到过时的错误消息非常令人困惑。从命令行运行dotnet builddotnet test时,一切正常。

我现在定位netstandard1.5因为,根据我能够收集的信息,它有parity with .NET Framework 4.6.2,我在此工作之前就已将其定位。

以下是project.json的最终版本:

Common\project.json

{
  "name": "<redacted>",
  "version": "2.0.0-*",
  "description": "<redacted>",
  "copyright": "<redacted>",
  "title": "<redacted>",
  "authors": [ "<redacted>" ],
  "language": "en-US",
  "packOptions": {
    "tags": [
      "GM",
      "UAS",
      "Common"
    ],
    "iconUrl": "<redacted>",
    "repository": {
      "type": "git",
      "url": "<redacted>"
    }
  },
  "buildOptions": {
    "xmlDoc": true,
    "compile": {
      "include": [
        "GlobalAssemblyInfo.cs"
      ]
    }
  },
  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.5": {}
  }
}

UnitTests\project.json

{
  "version": "0.0.0",
  "testRunner": "nunit",
  "dependencies": {
    "NUnit": "3.4.0",
    "dotnet-test-nunit": "3.4.0-beta-2",
    "Common": {
      "target": "project"
    }
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "portable-net45+win8",
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.0-*",
          "type": "platform"
        }
      }
    }
  }
}