我可以为生产装配和单元测试装配提供最简单的解决方案设置。首先,这是相关的配置:
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
项目?
另外两个较小的问题:
portable-net45+win8
导入问题?Microsoft.NETCore.App
:1.0.1。最初,project.json
引用了1.0.0版本,因此我对其进行了更改。但是,在Solution Explorer中,我仍然看到1.0.0。参考文献:
http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/
答案 0 :(得分:0)
事实证明,我所看到的几乎所有内容都只是工具问题。我希望微软尽快解决这个问题。在错误列表中看到过时的错误消息非常令人困惑。从命令行运行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"
}
}
}
}
}