C# "CS0006: Metadata file could not be found" in CI
The compiler needed a referenced assembly DLL that does not exist - almost always because a referenced project failed to build first, so its output was never produced. CS0006 is a symptom; the real failure is upstream.
What this error means
Build fails with CS0006 naming a .dll (often under another project’s bin/obj) that "could not be found". A referenced project earlier in the build failed or was skipped, so the consumer cannot find its output.
CSC : error CS0006: Metadata file
'/src/Shared/bin/Release/net8.0/Shared.dll' could not be foundCommon causes
A referenced project failed to build
When Shared fails to compile, its Shared.dll is never produced, and the consuming project then fails CS0006 looking for it. The first error in the log is the true cause.
Build order / parallelism produced a stale reference
A broken incremental state, or building a single project without its dependencies, can leave a referenced output missing.
How to fix it
Fix the first failing project
Scroll to the earliest error in the log - the referenced project’s real failure - and fix that; CS0006 then disappears.
dotnet build MyApp.sln -c Release
# read the FIRST error, not the CS0006 that follows itBuild the solution and clean stale state
Build the whole solution so dependencies build first, and clear stale outputs if incremental state is broken.
dotnet clean
dotnet build MyApp.sln -c ReleaseHow to prevent it
- Build the solution (so project references build in order) rather than isolated projects.
- Treat CS0006 as "look for the earlier failure", not as the root cause.
- Run a clean build in CI to avoid stale incremental outputs.