MSBuild error: "Could not resolve this reference. Could not locate the assembly..."

19,443

Add a project reference to the MyAssembly project, not a reference to the compiled output. Right click on the References node of the project which needs MyAssembly.dll, go to "Add Reference", then choose "Solution":

Solution reference


Say you have two projects (X and Y) with Y depending on X. Visual Studio will build X first, then Y.

You can add a reference to X in Y in one of two ways:

  • Reference the project in the solution
  • Reference the compiled output in the \bin\Debug folder

If the reference is to the project in the solution, then Visual Studio will know which order to compile your projects (X, then Y in our example).

If the reference is to the output in \bin\Debug, then Visual Studio won't know which order to compile the assemblies, and could try to compile Y before X, not find the file in \bin\Debug, and not compile.

Share:
19,443
M.Y. Babt
Author by

M.Y. Babt

Updated on June 15, 2022

Comments

  • M.Y. Babt
    M.Y. Babt almost 2 years

    I am aware that there is already a question here asking about the exact same error message, but unfortunately the accepted answer doesn't work for me.

    I was able to build my current solution successfully earlier this morning, but the build suddenly started failing ~15 minutes ago, with the following error message:

    C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "MyAssembly.dll". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

    Unfortunately for me, this DLL is required by my code. Because it cannot be located, my solution won't compile.

    I have tried cleaning and then building my solution again, but that was useless.

    I noticed that there was a yellow icon next to this reference, so I removed the reference and then added it again from the exact same location specified inside the <HintPath> tag in my .csproj file. (The location was the \bin\Debug folder.) The yellow icon then disappeared.

    However, immediately after I clicked on "Build solution" (in Debug mode), the yellow icon appeared again, and once more I saw the same MSBuild error message, informing me that the DLL could not be located.

    How can I resolve this issue?

  • yairr
    yairr over 5 years
    My issue was buried 3 levels deep. This answer helped me find it.