views:

98

answers:

1

Every now and then when I build my solution here (with 7 projects in it) I get the dreaded 'Command copy exited with code 4' error, in Visual Studio 2010 Premium ed.

This is because of the post-build event not being able to go through.

Here's what solves the problem, temporarily

  • Sometimes: A restart of Visual Studio and I'm able to build the solution
  • Sometimes: Both a restart of Visual Studio and my file manager of choice (Q-Dir 4.37) solves it.

Here's what the post-build event looks like:

xcopy "$(SolutionDir)Solution Items\References\*.dll" "$(TargetDir)" /Y

When you get the command copy exited with code [insert value] error, it's normally because of the following:

  • read / write permissions
  • missing files
  • wrong directories

However - obviously at times when I build the solution, there's no problem.

FYI, I uninstalled ReSharper 5.1.1 two weeks ago and Visual Studio's been giving me some errors since then (among them not being able to debug). I re-installed Visual Studio and it's working better since then, but still get this problem. Could it have to do with some ReSharper stuff being somewhere?

Have you had the same problem and solved it? Or do you have any possible solution to it?

Cheers.

A: 

I've invariably found this to be a file locking issue. Code 4 is Cannot Access File. One partial solution I found is to use the /C option for xcopy (which continues on error). Not really a solution but mostly it has stopped my builds from failing.

Another solution which only works on 32 bit is to use the unlocker tool to release the windows handles on the file before the copy.

Edit: I've just realised that it works under 64 bits too.

Preet Sangha
I added the /C option to above xcopy command and the build succeded. Thanks!Unlocker is invaluable at times.
Martin S.