This just saved me loads of time(especially because it only happened every once in a while):
if you encounter the amazingly annoying "Cannot copy file because it is being used by another process" when you want to rebuild or rerun a project in vs (for me it was always the test project), you can put the following in the pre-build event of the project that is having problems:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
for me personally the problem was a specific file that my project was testing against that was locked, so I changed it to be the following:
if exist "SOME_DLL.locked" del "SOME_DLL.locked"
if not exist "SOME_DLL.locked" move "SOME_DLL" "SOME_DLL.locked"