Search code examples
c#nugetnunit.net-6.0dotnet-test

Running "dotnet test" causes referenced project to not have nuget reference?


So we're upgrading some unit test projects to dotnet 6 from framework4.7.2. But there are some issues apparently:

When trying to run "dotnet test" in a dotnet 6 project that references a framework4.7.2 project, that has NUGETS installed, we get an error on that framework4.7.2 project that it's missing an assembly or using directive to the NUGET packages.

For your comfort I've created this small "diagram":
(A, B, C are projects // the "arrow" means "references")
(project A is an NUnit UNIT TEST project!)

A (net6.0) → B (framework4.7.2) → C (framework4.7.2) that has NUGET packages
⇒ ERRORs
A (net6.0) → C (framework4.7.2) that has NUGET packages
⇒ ERRORs
A (framework4.7.2) → B (framework4.7.2) → C (framework4.7.2) that has NUGET packages
⇒ Test pass!
A (net6.0) → NUGETs installed in the net6.0 project
⇒ Test pass!
A (net6.0) → B (framework4.7.2) with NO NUGETS
⇒ Test pass!

So running "dotnet test" in a framework4.7.2 project works, but running it in a net6.0 project we get the following error (for example this is thrown in project C from above when running "dotnet test" in project A, the net6.0 project):

enter image description here

HOWEVER all code compiles, builds, restores nuget etc. correctly. In the VS Test Explorer we find the tests, we can run them & they all succeed.

Does anyone know why this is the case?
Is it a .net version problem/incompatability issue?
Is it a test runner issue?
Is it NUnit?


Solution

  • I've found the answer to my issue!

    The issue was with the fact that their framework4.7.2 projects had an "Exe" in their respective .csproj-files. This was done because they used some assembly redirects (legacy stuff) and that can only be done in an EXE so I was told. When upgrading some projects to net6.0, they left that "OutputType" in there. The problem was explained to me by some senior from another team that it was something to do with managed and unmanaged code. That net6.0 projects you can't run the EXE anymore (or not with the assembly redirecting stuff) so I had to select the ".dll" files and run "dotnet test" on those.

    And it works! Running "dotnet test" locally or in pipeline on the specific ".dll"-file for those net6.0 projects do actually execute the tests! And then for the old projects I still go looking for the EXE to run.

    If anyone else has this issue, hope this explanation helps!