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

  Kiến thức lập trình

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” // NOK = not OK)
(project A is an NUnit UNIT TEST project!)

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

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?

LEAVE A COMMENT