MSBuild error MSB3021 / MSB3027: Unable to copy file — being used by another process
.NET 8 / 9 SDK, Visual Studio 2022, MSBuild, Windows Defender / IIS AppPool
error MSB3021: Unable to copy file "obj\Release\net8.0\App.dll" to "bin\Release\net8.0\App.dll". The process cannot access the file because it is being used by another process.
What it means (root cause)
A lingering dotnet.exe build server, MSBuild.exe node, Visual Studio VBCSCompiler, IIS w3wp.exe worker, or Windows Defender real-time scan holds an open file handle on the output binary.
The symptom developers actually see: error MSB3021: Unable to copy file "obj\Release\net8.0\App.dll" to "bin\Release\net8.0\App.dll". The process cannot access the file because it is being used by another process.
Step-by-step fix
Concrete, ordered steps from the dataset. Apply them in order; each line is a verified action, not generic advice.
- 1Shut down lingering MSBuild / Roslyn build servers cleanly: dotnet build-server shutdown
- 2Find and terminate any orphaned process locking the bin folder in PowerShell: Get-Process dotnet, MSBuild, VBCSCompiler -ErrorAction SilentlyContinue | Stop-Process -Force
- 3If deploying over an active IIS site, stop the AppPool first: Stop-WebAppPool -Name "DefaultAppPool"
- 4Disable node reuse in CI pipelines to prevent handle retention: dotnet build -nr:false
Where this error appears
Languages, frameworks, and runtimes where this error is observed (from the 2026 DevFixPro error dataset, retrieved 2026-08-29):
Frequent Windows build-pipeline and Visual Studio locking failure.
How to prevent it & common questions
Practical prevention plus the questions developers ask most about this error.
What does "MSBuild error MSB3021 / MSB3027: Unable to copy file — being used by another process" mean?
A lingering dotnet.exe build server, MSBuild.exe node, Visual Studio VBCSCompiler, IIS w3wp.exe worker, or Windows Defender real-time scan holds an open file handle on the output binary.
Which environments are affected by MSBuild error MSB3021 / MSB3027: Unable to copy file — being used by another process?
.NET 8 / 9 SDK, Visual Studio 2022, MSBuild, Windows Defender / IIS AppPool
How do I fix MSBuild error MSB3021 / MSB3027: Unable to copy file — being used by another process?
Shut down lingering MSBuild / Roslyn build servers cleanly: dotnet build-server shutdown Find and terminate any orphaned process locking the bin folder in PowerShell: Get-Process dotnet, MSBuild, VBCSCompiler -ErrorAction SilentlyContinue | Stop-Process -Force If deploying over an active IIS site, stop the AppPool first: Stop-WebAppPool -Name "DefaultAppPool" Disable node reuse in CI pipelines to prevent handle retention: dotnet build -nr:false
How do I prevent MSBuild error MSB3021 / MSB3027: Unable to copy file — being used by another process?
Add -nr:false (nodeReuse=false) to CI build commands and exclude repo bin/obj directories from real-time AV scanning.
Related DevFixPro tools
No dedicated DevFixPro tool maps to this error yet. Browse the full client-side toolkit instead: all developer tools →
Sources & attribution
- Error records aggregated from Google Search Console query gaps (2026-05-21~2026-08-18) for devfixpro.com, plus official framework docs (MDN, Node.js docs, Python docs, Go.dev, Rust book, Oracle Java docs, Docker docs, npm docs). Source dataset retrieved 2026-08-29. License: CC BY 4.0 — attribute DevFixPro (devfixpro.com).
- Official reference: https://learn.microsoft.com/en-us/visualstudio/msbuild/errors/msb3021
- All cause, environment, fix and prevention text on this page is taken verbatim from the DevFixPro 2026 error dataset. DevFixPro does not invent root causes or fixes.
How this MSBuild error MSB3021 / MSB3027: Unable to copy file — being used by another process page is built
Each error page is generated from a single record in the DevFixPro 2026 error dataset. The meaning, root cause, environments, fix steps, prevention, and official references are copied verbatim from that dataset and its official-doc sources; related-error links are computed from the error's category and explicit peer list. No root cause or fix is invented. The retrieval date for this dataset is 2026-08-29.