简体   繁体   English

将.NET标准库添加到.NET Framework项目后,测试未显示在测试浏览器中

[英]Tests not showing up in test explorer after adding .NET standard library to .NET framework project

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. 将.NET标准库添加到.NET Framework 4.6.1 Web api 2项目后,测试浏览器中没有测试显示。 (I am using MSTest) (我正在使用MSTest)

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. 如果我删除了.NET标准库,并且在添加时对其进行了所有应用和网络配置更改,则测试会再次显示。

My solution consists of: 我的解决方案包括:

  • Project A - .NET 4.6.1 web api referencing a .NET standard library 引用.NET标准库的Project A-.NET 4.6.1 Web API
  • Project B - .NET 4.6.1 unit test project; 项目B-.NET 4.6.1单元测试项目; referencing A 引用A

What I did: 我做了什么:

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

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

I didn't enable PackageReference as mentioned in the github issue but my WebAPI project works fine. 我没有启用github问题中提到的PackageReference,但是我的WebAPI项目运行正常。 Its just that my unit tests have dissappeared from the test explorer. 只是我的单元测试从测试浏览器中消失了。

I tried the solution from this question , but that hasn't helped. 我从这个问题尝试了解决方案,但这没有帮助。

You also need to add the .NET Standard library to the test project itself. 您还需要将.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. 由于经典项目(例如Web API项目)不支持可传递引用,因此您还需要将新项目添加到测试项目中。 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 Standard参考,并添加兼容性库并执行绑定重定向生成(由于添加的属性)。

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

相关问题 .NET Framework 4.7项目中的.NET标准类库 - .NET Standard Class Library in .NET Framework 4.7 project 尝试在 .Net Standard 项目中设置实体框架核心 - Trying to set-up Entity Framework core in .Net Standard project .net 标准库在 .net 核心中失败,但在框架中失败 - .net standard library fails in .net core but not in framework .Net Framework dll无法处理.Net标准项目 - .Net Framework dll not working on .Net Standard project Visual Studio .NET标准库和.NET Framework项目-NuGet dll清单定义不匹配 - Visual Studio .NET Standard library and .NET Framework project - NuGet dll manifest definition does not match 我可以使用.Net标准库中的PowerShell类在.Net Framework项目(exe)中使用吗 - Can I use PowerShell class in .Net Standard library to use in .Net Framework project (exe) 将 class 库项目升级到 .net 标准 2.1,其中 .net 框架 4.X 项目已引用该标准 - Upgrading class library project to .net standard 2.1 where this has been referenced by .net framework 4.X projects 如何将 .NET 标准库更改为 .NET 框架库? - How can I change a .NET standard library to a .NET framework library? 无法在 .NET 标准 2 项目中使用实体框架 - Cannot use Entity Framework in .NET standard 2 project 从.NET Framework传统项目引用.NET Standard csproj项目 - Referencing .NET Standard csproj project from .NET Framework traditional project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM