I am writing an ASP.NET web application using Visual Studio 2008. The project is mostly unchanged from the default empty project that Visual Studio provides, except for:
copy /y "$(TargetDir)$(TargetName).XML" "C:\TEMP\"
When I build the project for the first time, or rebuild, the build process completes successfully. If I try to build any time after that, however, the build process fails with this message:
------ Build started: Project: MyProject, Configuration: Debug Any CPU ------
MyProject -> C:\Projects\MyProject\MyProject\bin\MyProject.dll
copy /y "C:\Projects\MyProject\MyProject\bin\MyProject.XML" "C:\TEMP\"
The system cannot find the file specified.
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(3397,13): error MSB3073: The command "copy /y "C:\Projects\MyProject\MyProject\bin\MyProject.XML" "C:\TEMP\"" exited with code 1.
Done building project "MyProject.csproj" -- FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
I'm certain that the syntax is correct, because I can perform the post-build command in a command window:
C:\>copy /y "C:\Projects\MyProject\MyProject\bin\MyProject.XML" "C:\TEMP\"
1 file(s) copied.
The command works when I do it manually, so why does it fail when it is part of the build process?
There is a flaw in the underlying msbuild tasks that are used by Visual Studio when the XML documentation file is generated in the same directory as the one specified as the output path, for intermediary builds.
To fix it, you need to specify a different directory, for example, like this:
and change your post-build copy command accordingly, like this:
copy /y "C:\Projects\MyProject\MyProject\docbin\Debug\MyProject.XML" "C:\TEMP\"