Why does xcopy exit with code 9009 in Visual Studio post-build step?

This error can occur if your system PATH environment variable has been set incorrectly. The path should contain (at the very least)

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;

on modern versions of Windows (see https://superuser.com/questions/124239/what-is-the-default-path-environment-variable-setting-on-fresh-install-of-window). I have just found my system PATH had been set to

C:\Program Files (x86)\Bad Vendor\Buggy Program;

by an msi installer that obviously has issues.

If you don't know how to edit the PATH via the System Properties dialog, check out this link : http://support.microsoft.com/kb/310519 - it's basically the same in Windows 7 & 8 as it is in XP.

Finally, it's worth noting that a lot of programs don't notice if you update the PATH while they are running, so closing down and re-opeing programs like Visual Studio or command prompt windows will be required for the repaired path to take effect.


I encounted this error on the TeamCity build server. I finally resolved it after checking the build log and found:

"'xcopy' is not recognized as an internal or external command."

I then changed my statement to:

C:\Windows\System32\xcopy "$(ProjectDir)config\Web.config.$(ConfigurationName)" "$(ProjectDir)Web.config" /Y/R


Found my answer: The command had a line break between the source and destination strings. So, Visual Sudio was treating it as two commands. Eliminating the line break solved the problem.


Restart Visual Studio. Worked for me