Unable to copy file "obj\Debug\xyz.dll" to "bin\Debug\xyz.dll".
Unable to copy file "obj\Debug\xyz.dll" to "bin\Debug\xyz.dll". The process
cannot access the file 'bin\Debug\xyz.dll' because it is being used by
another process.
I have been getting this error on the project I am working on for quite some time now. It is an annoying error as the only solution before was to restart the IDE which in my case was a headache as it would take 10 minutes to reload being such a big project. In doing some research, I discovered that the library that was locking up was doing so because of the way it was being referenced in regards to its project and other project. It seems if you have a library that is referenced by a library in another project and that 2nd project library is referenced in a 3rd project library, then reference the third project library in the 1st project and then debug through the system, i.e. step through some code, stop the program, re-compile, and this problem will occur.
Alternative attempts to solve this issue:
I first tried to resolve this issue by unlocking to dll from whatever process it was attached to. I used Unlocker 1.85. It is a nice tool that displays what processes are currently attached to a library. It enables you to unlock those processes or kill them. You can download this tool at http://ccollomb.free.fr/unlocker/. I have used this tool in the past for similar issues. However, after I unlocked my particular dll in question and re-compile my code, I still got that error.
Re-start the IDE. Obviously this solution is not acceptable, as I stated before.
Final solution:
VS basically locks the file and you cannot use third party resources to unlock it. Therefore, just use VS! In the Properties of a project in your IDE you have Buld Events. Basically, you can write scripts during pre and post builds of a project. I added these two lines in the pre-build event command line, which basically unlocks the dll within Visual Studio.
IF EXIST $(TargetPath).LOCKED (del $(TargetPath).LOCKED) ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))
Re-compiled and your unable to copy dll error will not occur. I have spent the last day in coding harmony as I have not had to re-start my IDE! <g>