0

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)

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.

My solution consists of:

  • Project A - .NET 4.6.1 web api referencing a .NET standard library
  • Project B - .NET 4.6.1 unit test project; referencing A

What I did:

  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):

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

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.

os blue
  • 93
  • 6

1 Answers1

1

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

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).

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217