无法使 .NET Core NUnit 测试项目对我的生产 class 库的引用正常工作
Cannot get .NET Core NUnit test project's reference to my production class library to work
我为生产装配和单元测试装配设置了最简单的解决方案。首先,这里是相关配置:
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
这是怎么回事?我已经按照我能找到的所有教程尝试设置这些项目,但其中 none 有效。也许自教程创建以来 .NET Core 领域发生了变化?我需要更改什么才能让 UnitTests
项目识别我的 Common
项目?
另外两个较小的问题:
- 我是 运行 Windows 7 SP1。这会对
portable-net45+win8
导入造成问题吗?
Microsoft.NETCore.App
有更新版本:1.0.1。本来project.json
引用的是1.0.0版本,所以改了下。但是,在解决方案资源管理器中,我仍然看到 1.0.0.
参考文献:
http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/
事实证明,我所看到的几乎所有内容都只是工具问题。我希望微软能尽快解决这个问题;在错误列表中看到过时的错误消息非常令人困惑。当从命令行 运行 dotnet build
和 dotnet 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"
}
}
}
}
}
我为生产装配和单元测试装配设置了最简单的解决方案。首先,这里是相关配置:
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
这是怎么回事?我已经按照我能找到的所有教程尝试设置这些项目,但其中 none 有效。也许自教程创建以来 .NET Core 领域发生了变化?我需要更改什么才能让 UnitTests
项目识别我的 Common
项目?
另外两个较小的问题:
- 我是 运行 Windows 7 SP1。这会对
portable-net45+win8
导入造成问题吗? Microsoft.NETCore.App
有更新版本:1.0.1。本来project.json
引用的是1.0.0版本,所以改了下。但是,在解决方案资源管理器中,我仍然看到 1.0.0.
参考文献:
http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/
事实证明,我所看到的几乎所有内容都只是工具问题。我希望微软能尽快解决这个问题;在错误列表中看到过时的错误消息非常令人困惑。当从命令行 运行 dotnet build
和 dotnet 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"
}
}
}
}
}