C# "CS0006: Metadata file could not be found" in CI
CS0006 means the compiler was told to reference an assembly that is not on disk. In CI it usually means a referenced project failed to build first, or projects built in the wrong order, so the expected .dll was never produced. The real failure is often the upstream project's earlier error.
What this error means
Build fails with CS0006 naming a .dll path under a sibling project's bin/. The upstream project usually has its own earlier error that is the true root cause.
error CS0006: Metadata file 'D:\a\repo\src\Core\bin\Release\net8.0\Core.dll'
could not be foundCommon causes
The referenced project failed to build
The dependency project errored earlier, so its output assembly was never written and the consuming project cannot find it.
Build order or missing ProjectReference
A raw assembly reference (instead of a ProjectReference) means MSBuild does not know to build the dependency first.
How to fix it
Fix the upstream project error first
- Scroll up in the log to find the first failing project's real error.
- Resolve that error so its assembly builds.
- Rebuild the solution.
Use ProjectReference, not a raw HintPath
- Reference the dependency as a
ProjectReferenceso MSBuild orders the build correctly. - Build the whole solution rather than a single project in isolation.
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>How to prevent it
- Always reference sibling projects via
ProjectReference. - Build the solution, not individual projects, so dependencies build first.
- Read the first error in the log, not the cascading CS0006.