c# - 使用 xUnit 处理 netstandard1.6

标签 c# xunit .net-core

我希望为 netstandard1.6 库使用测试框架。我试着关注和编辑Getting started with xUnit.net (.NET Core / ASP.NET Core)没有成功。按照 xUnit 的教程在 VS 2015 Update 3 RTM 上使用 dotnetcore lib 和我的 project.json 文件重现错误。

项目.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": {}
  }
}

错误:

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

我可以降级到 dotnet-test-xunit 2.2.0-preview2-build1029 支持的 .netstandard 版本吗?是否有任何已知的解决方法可以将 xUnit 与它一起使用?

由于我对 project.json 和 dotnetcore 有点陌生,我可能会错过一些有用的东西。

最佳答案

这对我有用。似乎现有的 xunit 版本还不支持 netstandard 1.6 库。尝试更改您的项目 json,使其看起来像 xunit site 中提供的那样.这还假设您创建了一个 .net 核心库项目

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

关于c# - 使用 xUnit 处理 netstandard1.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38120169/

相关文章:

c# - 异步任务的许多实例可以共享对并发集合的引用,并在C#中向其中并发添加项目吗?

async-await - 为什么这个 xunit 测试死锁(在单个 CPU 虚拟机上)?

c# - 我的 XUnit dotnet 核心项目在我的桌面上构建,但不在 DevOps Server 2019 中构建

c# - 使用单个巨大任务(例如 SQL 查询)杀死/中止线程

c# - 链表设计

c# - 使用 ReSharper,如何在长时间运行的单元测试期间显示调试输出?

.net - dotnet test 不会使用通配符递归搜索文件夹中的 .csproj

c# - 如何动态获取程序集名称

c# - 将 Serilog.Sinks.MsSqlServer 与 Entity Framework Core 结合使用

c# - 从消息体中读取多个参数