Handle netstandard1.6 with xUnit

风流意气都作罢 提交于 2019-12-01 16:41:40

问题


I am looking to use a test framework for a netstandard1.6 library. I tried to follow and edit Getting started with xUnit.net (.NET Core / ASP.NET Core) without success. Follow the xUnit's tutorial with a dotnetcore lib on VS 2015 Update 3 RTM with my project.json file to reproduce the error.

project.json :

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "xunit": "2.2.0-beta2-build3300",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
  },
  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

Error:

Severity    Code    Description
Error       NU1002  The dependency dotnet-test-xunit 2.2.0-preview2-build1029 does not support framework .NETStandard,Version=v1.0

Can I downgrade to a version of .netstandard supported by dotnet-test-xunit 2.2.0-preview2-build1029? Is there any known work around to use xUnit with it?

As I am a bit new project.json and dotnetcore, I might missed something useful.


回答1:


This worked for me. It seems existing xunit versions do not support the netstandard 1.6 library yet. Try changing your project json to look like this as provided for in xunit site. This also assumes that you created a .net core library project

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "dependencies": {
    "xunit": "2.2.0-beta2-build3300",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
  },
  "frameworks": {
    "netcoreapp1.0": {
       "dependencies": {
          "Microsoft.NETCore.App": {
             "type": "platform",
             "version": "1.0.0"
           }
         }
      }
   }
}



回答2:


You can import the netcoreapp1.0 TFM to convince the tooling that the dependencies are compatible with the target framework:

{ 
  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "xunit": "2.2.0-beta4-build3444",
    "dotnet-test-xunit": "2.2.0-preview2-build1029" 
  },
  "frameworks": {
    "netstandard1.6": {
      "imports": [ "netcoreapp1.0" ]
    }
  }
}

You can find a table of target framework monikers (TFM) in the NuGet documentation linked below, including a table of deprecated frameworks which includes dnxcore50 (replaced by netcoreapp1.0):

https://docs.nuget.org/ndocs/schema/target-frameworks




回答3:


I suggest using the following versions (this is the same, as in asp.net core repos like Logging:

"dotnet-test-xunit": "1.0.0-*",
"xunit": "2.1.0"



回答4:


  1. Check the available versions for the xunit dependency. I think the 2.2.0 is already final.

  2. A xunit project needs to be netcoreapp1.0 and not netstandard.

See their web page for details.




回答5:


The .NET CLI tool (dotnet) support creating a test project:

testproj $ dotnet new -t xunittest
Created new C# project in /home/bartonjs/dotnet/testproj.
testproj $ cat project.json

Produces:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {
    "System.Runtime.Serialization.Primitives": "4.1.1",
    "xunit": "2.1.0",
    "dotnet-test-xunit": "1.0.0-rc2-192208-24"
  },
  "testRunner": "xunit",
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      },
      "imports": [
        "dotnet5.4",
        "portable-net451+win8"
      ]
    }
  }
}

Those versions might better lead to success.



来源:https://stackoverflow.com/questions/38120169/handle-netstandard1-6-with-xunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!