NathanAldenSr NathanAldenSr - 2 months ago 26
C# Question

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
:

{
"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"
}
}
}
}
}


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? What do I need to change to get the
UnitTests
project to recognize my
Common
project?

Two other smaller concerns:


  1. I'm running Windows 7 SP1. Does that pose a problem with the
    portable-net45+win8
    import?

  2. There is a newer version of
    Microsoft.NETCore.App
    : 1.0.1. Originally,
    project.json
    was referencing version 1.0.0, so I changed it. However, in Solution Explorer, I still see 1.0.0.



References:

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

Answer

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.

I am now targeting netstandard1.5 because, from what I'm able to gather, it has parity with .NET Framework 4.6.2, which we were targeting prior to this work.

Here are the final versions of 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"
        }
      }
    }
  }
}