3
votes

I'm trying to create a new PCL library (along with a new Windows Universal app), and I've created a new project to start writing my unit tests using xUnit. I've added nuget references to xunit, as well as xunit.runner.visualstudio. I'm using Visual Studio 2015 RTM, as well as Resharper 9.1, and bother of them give me a similar error when trying to run or discover the unit tests. This is from visual studio:

------ Discover test started ------

[xUnit.net 00:00:00.2661814] Skipping: WinBlur.NewsBlurClient.Tests (could not find dependent assembly 'xunit.core, Version=2.1.0')

[xUnit.net 00:00:00.2235684] Skipping: WinBlur.NewsBlurClient.Tests (could not find dependent assembly 'xunit.core, Version=2.1.0')

========== Discover test finished: 0 found (0:00:00.6920785) ==========

This output shows trying to use the latest beta versions of 2.1, but I've tried both the current release version (2.0.0) as well and I get the same result.

Here's my project.json file:

{
  "supports": {
    "net46.app": {},
    "uwp.10.0.app": {}
  },
  "dependencies": {
    "Microsoft.NETCore": "5.0.0",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.0",
    "xunit": "2.0.0",
    "xunit.core": "2.0.0",
    "xunit.assert":  "2.0.0",
    "xunit.runner.visualstudio": "2.0.1"
  },
  "frameworks": {
    "dotnet": {
      "imports": "portable-net452+win81"
    }
  }
}

When I added the nuget reference to xunit, it did not originally add the dependencies for xunit.core and xunit.assert, so I added those myself to see if it helped, but no luck.

2
I'm having the same problem. Adding xunit.core and xunit.assert explicitly shouldn't have any effect, so I suggest you remove them. FYI there is another discussion with a very similar problem here, that might help you: github.com/NuGet/Home/issues/1084Andrew Arnott

2 Answers

2
votes

xUnit.net is broken with modern PCLs right now.

The bug is that modern PCLs (or any class library which uses project.json instead of packages.config) don't copy the referenced DLLs. This is a bug in Visual Studio's support for project.json with class libraries, and will have to be fixed by the Microsoft team.

3
votes

A workaround (at least for some libraries) is that you can add these properties to your project file:

<PropertyGroup>
    <CopyNuGetImplementations>true</CopyNuGetImplementations>
    <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

After that, xunit works with project.json. At least for me.