Fix: Cannot copy file 'X' to file 'Y'. The process cannot access the file because it is being used by another process. in Visual Studio 2008 - ISerializable - Roy Osherove's Blog

Fix: Cannot copy file 'X' to file 'Y'. The process cannot access the file because it is being used by another process. in Visual Studio 2008

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"

Published Wednesday, April 09, 2008 4:21 AM by RoyOsherove
Filed under:

Comments

Saturday, April 12, 2008 12:05 PM by pb

# re: Fix: Cannot copy file 'X' to file 'Y'. The process cannot access the file because it is being used by another process. in Visual Studio 2008

I just disable the host in the project properties debugging tab.. Not sure what it is supposed to do anyway, never notice a difference once I disable it.

Wednesday, June 18, 2008 8:05 AM by Brian Mains Blog

# Locked Files Problem in VS 2008

I had an issue where I had a locked file in VS 2008, and I couldn't compile a project because it