question

RodAtWork avatar image
0 Votes"
RodAtWork asked RodAtWork commented

Getting a "could not be found" from the unit test project

I've made some changes to a ASP.NET MVC Core (.NET 6) solution. There's two projects; the MVC project and a xUnit test. Suddenly today, I started to get this error:

CS0006 Metadata file 'C:\Repos\PW\PharmacyWarehouseV2\PharmacyWarehouseV2\obj\Debug\net6.0\ref\PharmacyWarehouseV2.dll' could not be found PharmacyWarehouseV2.Test

So, it is coming from the xUnit project PharmacyWarehouseV2.Test. And it's trying to find a DLL which the build is supposed to create. So, how do I get around MSBuild complaining about what it should be creating?

vs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered RodAtWork commented

Generally you get this when the previous project fails to build. Try a clean build. Also ensure that you're using a project reference to the other project and not a binary reference. There is also the chance that it is related to using different target frameworks but you'd have to identify what changed between the working and non-working versions.

· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, @cooldadtx, for your response,

I've tried at least three clean builds, but that didn't help.

I've just double checked the xUnit test project. It has a project reference to the MVC project.

I've just checked both projects. They're both using .NET 6.

Thank you very much for making suggestions as to what I should check to help resolve this issue. Have you other suggestions?

0 Votes 0 ·

When the error occurs is the file actually on disk where it is looking for it? I'm assuming it is building successfully and that the build order is correct.

Do you have the latest test framework and test adapter installed for xUnit?

Turn on diagnostic debugging for the MSBuild and take a look at the build output for the test project. You're looking for warnings and errors.

0 Votes 0 ·

The .DLL is not in the folder where the test project is looking for it. That is significant. However, I would have expected MSBuild to "know" what order it should build the projects in: MVC project first, then the unit test project. After all, if there's anything like a MAKEFILE, I've no idea what that would be, for MSBuild. What I did was modify a view, a viewmodel class and the associated controller. Why that would make a difference to how MSBuild performs a build, when it never was a problem before, is a huge mystery to me.

There's an update to xUnit (also one for Moq, Microsoft.NET.Test.Sdk and something called coverlet.collector). I'll update the xUnit project, then let you know how it went...

... unfortunately, that didn't change anything.

Lastly, I've no idea how to turn on diagnostic debugging for MSBuild. How do I do that?

0 Votes 0 ·
Show more comments