Unable to copy file reference.dll to bin/reference.dll. The process cannot access the file reference.dll because it is being used by another process

The issue ended up being that in the web.config someone had added:

hostingEnvironment shadowCopyBinAssemblies="false"

After commenting this out, everything started building ok. What a nightmare!!


Use ProcessExplorer to find out what process has the file open and go from there.

If a process is currently using those DLL, you can't delete and re-write it. You'll have to kill or otherwise stop the process using those DLLs while you compile.


I have battled this issue FOR YEARS!

Have you tried adding this to your PREBUILD Event?

if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

See this for more info: http://nayyeri.net/file-lock-issue-in-visual-studio-when-building-a-project

Here's another thread, with more things to try...

http://social.msdn.microsoft.com/forums/en-US/Vsexpressinstall/thread/5b71eb06-5047-483d-8fd3-b75c102d41e9/?prof=required