【问题标题】:Handle netstandard1.6 with xUnit用 xUnit 处理 netstandard1.6
【发布时间】:2016-06-30 10:14:43
【问题描述】:

我希望为 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 有点陌生,我可能会错过一些有用的东西。

【问题讨论】:

    标签: c# xunit .net-core


    【解决方案1】:

    这对我有用。似乎现有的 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"
               }
             }
          }
       }
    }
    

    【讨论】:

      【解决方案2】:

      您可以导入 netcoreapp1.0 TFM 以使工具相信依赖项与目标框架兼容:

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

      您可以在下面链接的 NuGet 文档中找到目标框架名字对象 (TFM) 表,其中包括 弃用框架 表,其中包括 dnxcore50(已替换为 netcoreapp1.0):

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

      【讨论】:

        【解决方案3】:

        我建议使用以下版本(这与在 asp.net core repos 中类似Logging:

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

        【讨论】:

          【解决方案4】:
          1. 检查 xunit 依赖项的可用版本。我认为 2.2.0 已经是最终版本了。

          2. xunit 项目需要是 netcoreapp1.0 而不是 netstandard。

          查看他们的网页了解详情。

          【讨论】:

            【解决方案5】:

            .NET CLI 工具 (dotnet) 支持创建测试项目:

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

            产生:

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

            那些版本可能会更好地走向成功。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-08-25
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多