将 .NET 标准库添加到 .NET 框架项目后,测试未显示在测试资源管理器中 [英] Tests not showing up in test explorer after adding .NET standard library to .NET framework project

查看:27
本文介绍了将 .NET 标准库添加到 .NET 框架项目后,测试未显示在测试资源管理器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我将 .NET 标准库添加到 .NET 框架 4.6.1 web api 2 项目后,测试资源管理器中没有显示任何测试.(我正在使用 MSTest)

No tests are showing up in the test explorer after I added a .NET standard library to a .NET framework 4.6.1 web api 2 project. (I am using MSTest)

如果我删除 .NET 标准库和所有应用程序 &当我添加它时,它所做的 web 配置更改,测试再次显示.

If I remove the .NET standard library and all the app & web config changes it made when I added it, the tests show up again.

我的解决方案包括:

  • 项目 A - .NET 4.6.1 web api 引用 .NET 标准库
  • 项目 B - .NET 4.6.1 单元测试项目;引用 A

我做了什么:

  1. 将 .NET 标准库添加到我的 webapi 2 项目(项目 A)
  2. 遵循 这篇微软文章(最后一步)并在网络应用程序中启用自动绑定重定向
  3. 这在我的主 web.config 和我的单元测试项目的 app.config 中添加了很多程序集重定向.
  4. this github thread 之后,我将以下内容添加到我的单元测试项目中(项目 B):
  1. Added .NET standard lib to my webapi 2 project (Project A)
  2. Followed this microsoft article (last step) and enabled automatic binding redirects in web apps
  3. This added alot of assembly redirects in my main web.config and in the app.config of my unit tests project.
  4. Following this github thread, I added the following to my unit test project (Project B):

true<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

我没有像 github 问题中提到的那样启用 PackageReference,但我的 WebAPI 项目运行良好.只是我的单元测试从测试资源管理器中消失了.

I didn't enable PackageReference as mentioned in the github issue but my WebAPI project works fine. Its just that my unit tests have dissappeared from the test explorer.

我尝试了这个问题的解决方案,但这并没有帮助.

I tried the solution from this question, but that hasn't helped.

推荐答案

您还需要将 .NET Standard 库添加到测试项目本身.

You also need to add the .NET Standard library to the test project itself.

由于Web API项目等经典项目不支持传递引用,因此您还需要将新项目添加到测试项目中.然后测试项目的构建逻辑会看到.NET Standard 引用并添加兼容性库并执行绑定重定向生成(由于您添加的属性).

Since classic projects like the Web API project don't support transitive references, you also need to add the new project to the test project. Then the build logic of the test project will see the .NET Standard reference and add the compatibility libraries and perform the binding redirect generation (due to the properties you added).

这篇关于将 .NET 标准库添加到 .NET 框架项目后,测试未显示在测试资源管理器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆