[英]Cannot get .NET Core NUnit test project's reference to my production class library to work
I have the simplest solution setup possible for a production assembly and a unit tests assembly. 我可以为生产装配和单元测试装配提供最简单的解决方案设置。 First, here is the relevant configuration:
首先,这是相关的配置:
Common.sln
global.json
-- src
---- Common
------ project.json
-- test
---- UnitTests
------ project.json
global.json
: global.json
:
{
"projects: [ "src", "test" ]
}
Common\\project.json
: 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
: 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"
}
}
}
}
}
When I compile, I get these errors in the Error List: 当我编译时,我在错误列表中得到这些错误:
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
What's going on here? 这里发生了什么? I've followed every tutorial I can find to try and set these projects up, but none of them work.
我已经按照我可以找到的每个教程来尝试设置这些项目,但它们都不起作用。 Perhaps things have changed in .NET Core land since the tutorials were created?
自创建教程以来,.NET Core中的内容可能已经发生了变化? What do I need to change to get the
UnitTests
project to recognize my Common
project? 我需要更改什么才能让
UnitTests
项目识别我的Common
项目?
Two other smaller concerns: 另外两个较小的问题:
portable-net45+win8
import? portable-net45+win8
导入造成问题吗? Microsoft.NETCore.App
: 1.0.1. Microsoft.NETCore.App
。 Originally, project.json
was referencing version 1.0.0, so I changed it. project.json
引用了1.0.0版本,因此我对其进行了更改。 However, in Solution Explorer, I still see 1.0.0. References: 参考文献:
http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/ http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/
It turns out that nearly everything I was seeing was simply tooling issues. 事实证明,我所看到的几乎所有东西都只是工具问题。 I hope Microsoft addresses this soon;
我希望微软尽快解决这个问题。 it's very confusing to see stale error messages in the Error List.
在错误列表中看到过时的错误消息非常令人困惑。 Everything works fine when running
dotnet build
and dotnet test
from the command line. 从命令行运行
dotnet build
和dotnet test
时,一切正常。
I am now targeting netstandard1.5
because, from what I'm able to gather, it has parity with .NET Framework 4.6.2 , which I was targeting prior to this work. 我现在的目标是
netstandard1.5
因为从我能够收集的内容来看,它与.NET Framework 4.6.2相同 ,我在此工作之前就已将其作为目标。
Here are the final versions of project.json
: 以下是
project.json
的最终版本:
Common\\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
: 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"
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.