Getting a "could not be found" from the unit test project - Microsoft Q&A (2024)

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.

  1. Getting a "could not be found" from the unit test project - Microsoft Q&A (1)

    Rod At Work 866Reputation points

    2022-05-25T21:42:42.403+00:00

    Thank you, @Michael Taylor , 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?

  2. Getting a "could not be found" from the unit test project - Microsoft Q&A (2)

    Michael Taylor 53,316Reputation points

    2022-05-25T21:53:13.107+00:00

    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.

  3. Getting a "could not be found" from the unit test project - Microsoft Q&A (3)

    Rod At Work 866Reputation points

    2022-05-25T22:11:49.007+00:00

    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?

  4. Getting a "could not be found" from the unit test project - Microsoft Q&A (4)

    Michael Taylor 53,316Reputation points

    2022-05-26T14:31:40.323+00:00

    MSBuild compiles in the order given. If you have a project reference then the order will have the dependent project built after the dependee but you can verify the ordering by right clicking the solution in Solution Explorer and looking at the build order. But I doubt that it is an issue here.

    I'm assuming here the build for PharmacyWarehouseV2 is successful. Can you post the top level items from your project file for the MVC project and all the xUnit test project file contents? I'm curious if there is a mismatch somewhere.

    Alternatively create a new xUnit test project, add a dependency to the MVC project and compile. If that works then move your tests to the new project and try again.

  5. Getting a "could not be found" from the unit test project - Microsoft Q&A (5)

    Rod At Work 866Reputation points

    2022-05-26T20:06:42.317+00:00

    (I'm going to have to do this in multiple replies, because I've exceeded the character limit)

    Thank you for pointing out the "Project Build Order..." option when right-mouse button clicking on the solution. I did that and verified that the build order is correct.

    I guess PharmacyWarehouseV2 built successfully. When I did a Build Clean and rebuild solution, there was only one error, which is in PharmacyWarehouseV2.Test. However, that's because there is no .DLL located at C:\Repos\PW\PharmacyWarehouseV2\PharmacyWarehouseV2\obj\Debug\net6.0\ref\PharmacyWarehouseV2.dll. In fact, I just searched throughout the PharmacyWarehouseV2 project directory structure. There's no .DLL anywhere.

    Here's the top level items, including the PropertyGroup, from the PharmacyWarehouseV2

  6. Getting a "could not be found" from the unit test project - Microsoft Q&A (6)

    Rod At Work 866Reputation points

    2022-05-26T20:07:53.507+00:00

    <Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="KendoUIProfessional" Version="2022.1.412" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.2" />

  7. Getting a "could not be found" from the unit test project - Microsoft Q&A (7)

    Rod At Work 866Reputation points

    2022-05-26T20:08:20.847+00:00

    And here is PharmacyWarehouseV2.Test project file:

    <Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable> 

    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="Moq" Version="4.17.2" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.0">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    </ItemGroup>

    <ItemGroup>
    <ProjectReference Include="..\PharmacyWarehouseV2\PharmacyWarehouseV2.csproj" />
    </ItemGroup>

    </Project>

  8. Getting a "could not be found" from the unit test project - Microsoft Q&A (8)

    Michael Taylor 53,316Reputation points

    2022-05-26T20:33:19.943+00:00

    However, that's because there is no .DLL located at

    That's a problem then. When you build your web app it should generate the DLL into the given folder. It is that reference that the unit test project is going to try to use. So the problem is that the web project isn't generating the output file.

    Let's start simple here. When you build you should see a summary that says Build: X succeeded. If you add up the succeeded and failed projects it should total the projects in your solution. So if you just have the web app + unit test then it should be 2. If that number is off then something has gone wrong. At that point I'd be jumping into Configuration Manager and making sure the solution build is configured to build all the projects and their platforms correctly.

    If everything is right there then we need to move to the build output. Go to Tools\Options -> Projects and Solutions\Build and Run. Change the MSBuiild project build log file verbosity to Detailed and then do a clean build. Within that huge log file you should see where it is building your web project and the output directory it is using. That's what we need to look at.

  9. Getting a "could not be found" from the unit test project - Microsoft Q&A (9)

    Rod At Work 866Reputation points

    2022-05-26T20:51:21.3+00:00

    When I do a build I see the following:

    Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped

    Looking at Configuration Manager I see both projects have the Build checkbox, checked.

    I'm trying the detailed MSBuild project build log file verbodity option now. Where does it put that log file?

  10. Getting a "could not be found" from the unit test project - Microsoft Q&A (10)

    Rod At Work 866Reputation points

    2022-05-26T21:01:19.167+00:00

    FINALLY I found it! I was trying to find out where the log file was being written to. So, I scrolled up the Output window and saw that there was a warning (not an error) about a class not being found in a different view. I went to that view, removed the offending line, then tried to rebuild the app. It rebuilt fine and ran as well.

    Thank you, @Michael Taylor for your help!

Sign in to comment

Getting a "could not be found" from the unit test project - Microsoft Q&A (2024)

References

Top Articles
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6008

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.