简体   繁体   English

来自普通.net 4.6.2单元测试项目的参考netcoreapp1.0

[英]Reference netcoreapp1.0 from normal .net 4.6.2 unit test project

I have 2 projects. 我有2个项目。 One is a .Net Core Console App and one is a normal Unit Test Project. 一个是.Net Core Console App,另一个是普通的单元测试项目。

I want to add a Reference to the .Net Core App from the Unit Test Project. 我想从单元测试项目中添加对.Net Core App的引用。

When I try to add a reference to the Project, I get the following error: 当我尝试添加对项目的引用时,出现以下错误:

A reference to '{0}' could not be added. 无法添加对“ {0}”的引用。 An assembly must have a 'dll' or 'exe' extension in order to be referenced. 程序集必须具有'dll'或'exe'扩展名才能被引用。

When I then add a reference to the produced dll inside the bin folder, I can write my tests without any compile time errors, but the Tests won't show up in the Test Explorer. 然后,在bin文件夹中添加对生成的dll的引用时,我可以编写测试而没有任何编译时错误,但是测试不会显示在“测试资源管理器”中。

As soon as I remove the reference to the dll, And comment out any code relying on that dll, all Tests show up in the Test Explorer. 一旦删除对dll的引用,并注释掉所有依赖该dll的代码,所有测试就会显示在“测试资源管理器”中。

What do I have to do to make my Tests show up in the Test Explorer? 要使我的测试显示在“测试资源管理器”中,我该怎么做?

This is my project.json in the Console App: 这是控制台应用程序中的我的project.json:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true,
    "allowUnsafe": true
  },

  "dependencies": {
    "adremes.Data": "1.0.0",
    "MailKit": "1.10.0",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.Relational": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.Extensions.Configuration": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0",
    "Newtonsoft.Json": "9.0.1"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  },

  "runtimes": {
    "win7-x64": {}
  }
}

I had the same issue. 我遇到过同样的问题。 I solved it by manually adding a reference the .Net Core dll to the Unit test project. 我通过手动向单元测试项目中添加.Net Core dll引用来解决此问题。 Hopefully this will be solved in VS2017. 希望这将在VS2017中解决。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM