简体   繁体   English

无法获得.NET Core NUnit测试项目对我的生产类库的引用

[英]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 : global.json

{
  "projects: [ "src", "test" ]
}

Common\\project.json : 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 : 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? 自创建教程以来,.NET Core中的内容可能已经发生了变化? What do I need to change to get the UnitTests project to recognize my Common project? 我需要更改什么才能让UnitTests项目识别我的Common项目?

Two other smaller concerns: 另外两个较小的问题:

  1. I'm running Windows 7 SP1. 我正在运行Windows 7 SP1。 Does that pose a problem with the portable-net45+win8 import? 这会对portable-net45+win8导入造成问题吗?
  2. There is a newer version of Microsoft.NETCore.App : 1.0.1. 有更新版本的Microsoft.NETCore.App Originally, project.json was referencing version 1.0.0, so I changed it. 最初, project.json引用了1.0.0版本,因此我对其进行了更改。 However, in Solution Explorer, I still see 1.0.0. 但是,在解决方案资源管理器中,我仍然看到1.0.0。

References: 参考文献:

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

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. 从命令行运行dotnet builddotnet test时,一切正常。

I am now targeting netstandard1.5 because, from what I'm able to gather, it has parity with .NET Framework 4.6.2 , which I was targeting prior to this work. 我现在的目标是netstandard1.5因为从我能够收集的内容来看,它与.NET Framework 4.6.2相同 ,我在此工作之前就已将其作为目标。

Here are the final versions of project.json : 以下是project.json的最终版本:

Common\\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 : 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"
        }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引用 .net 核心类库到项目的问题 - Issue with reference .net core class library to project NUnit 测试项目的 .NET Core 容器定义 - .NET Core container definition for NUnit test project 如何在ASP Net Core项目中添加类库项目的引用 - How to add reference of class library project in asp net core project vs 2017 .net核心类库项目中的引用管理器为空 - Reference manager is empty in vs 2017 .net core class library project 在.NET 4.6项目中引用.NET Core Library - Reference a .NET Core Library in a .NET 4.6 project Nunit没有在测试项目类库(VS2012)中遇到断点 - Nunit not hitting breakpoints in test project class library (VS2012) 如何获得对 class 库项目的引用才能工作? - How do I get a reference to a class library project to work? 无法从完整.NET项目中引用.NET Core类库 - Unable to project reference a .NET Core Class Library from Full .NET Project 无法使 nunit 测试异常正常工作。使用 .net 2.0 - Cannot make nunit test exception to work .Using .net 2.0 将.NET Core类库引用添加到UWP应用时,显示“无法添加对项目的引用…”。 - When adding .NET Core class library reference to UWP app, it says “Unable to add a reference to project…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM