Skip to content
Latchkey

MSBuild "MSB3027: could not copy ... locked" Output File in CI

MSBuild could not copy a build output because the destination file is locked by another process. It retries, then fails MSB3027 ("being used by another process") - a still-running app, antivirus scan, or a concurrent build is holding the file.

What this error means

Build fails copying a .dll/.exe into bin/obj with MSB3027 after exhausting copy retries, saying the file is in use. It is often intermittent on Windows runners where a previous test process or scanner still holds the output.

MSBuild output
error MSB3027: Could not copy "obj/Release/MyApp.dll" to "bin/Release/MyApp.dll".
Exceeded retry count of 10. Failed.
error MSB3021: The process cannot access the file because it is being used by another process.

Common causes

A previous process still holds the output

A test host, a launched app, or a watcher from an earlier step is still running and has the output .dll/.exe open, blocking the copy.

Antivirus or a parallel build locking the file

Real-time antivirus scanning the output, or two builds writing the same bin, can momentarily lock the file and exhaust MSBuild’s copy retries.

How to fix it

Ensure prior processes have exited

Stop any app/test host that may still hold the output before rebuilding.

Terminal
# wait for / kill a lingering test host before rebuild (Windows)
taskkill /F /IM MyApp.exe /T 2>NUL
dotnet build -c Release

Avoid concurrent writes to the same output

  1. Do not run two builds/tests that write the same bin/obj in parallel on one runner.
  2. Exclude the build output directory from real-time antivirus scanning on the runner.
  3. Use a clean working directory per job so stale processes cannot hold outputs.

How to prevent it

  • Serialize steps that build/run the same project so no process holds the output during a copy.
  • Exclude bin/obj from antivirus scanning on CI runners.
  • Give each job an isolated workspace to avoid cross-build file locks.

Frequently asked questions

What causes ""MSB3027: ... being used by another process""?
A test host, a launched app, or a watcher from an earlier step is still running and has the output .dll/.exe open, blocking the copy.
How do I fix "MSB3027: ... being used by another process"?
Stop any app/test host that may still hold the output before rebuilding.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card