Visual Studio增量构建:XML文档文件创建太晚了

时间:2009-07-16 09:20:39

标签: visual-studio visual-studio-2005 msbuild

我有一个Visual Studio 2005的DLL项目,它打开了“XML文档文件”。 每当我进行增量构建时,在构建后事件执行期间,输出目录中都没有XML文档文件。

如果我在构建后事件期间暂停构建(使用来自GnuWin32 CoreUtils的sleep实用程序),我可以在输出目录中看到名为vs5BB5.tmp的文件。但是,在完成构建后事件(和“AfterBuild”目标,因为我在那里进行了一些自定义)之后,此文件不会重命名为MyLib.xml。

对于Studio中的干净构建和从命令行启动的MSBuild,一切都按预期工作 - 在构建后事件之前创建XML文档文件。

为什么会发生这种情况,以及如何修复增量构建?

3 个答案:

答案 0 :(得分:3)

刚刚遇到同样的问题。这是Visual Studio和增量构建的已知问题。请参阅this post on microsoft connect

我用条件xcopy解决了它,如下所示:

if exist "$(TargetDir)$(TargetName).xml" xcopy $(TargetDir)$(TargetName).xml $(ProjectDir)......\bin\ /C /I /R /Y

SF

答案 1 :(得分:1)

我自己就是这个问题....

我发现xml文件被命名为.tmp文件,因此您可以将此tmp文件复制到您想要的位置,这只是一个“混乱”的工作。

我也很想写一个命令行工具,它叫做: -

WaitForThenCopy <source path> <target path> <milliseconds to wait>

唯一的问题是它必须是非阻塞的,你不会知道它是否有效。

答案 2 :(得分:1)

我正在使用一个简单的批处理文件进行复制,而不是检测tmp文件的默认复制命令,而是复制/重命名。

REM There is a bug in VS where the xml documentation is written to a tmp file
REM during incremental builds, preventing access during post-build events.
REM See http://connect.microsoft.com/VisualStudio/feedback/details/470485/strange-file-not-found-error-xml-documentation-file-renamed-during-incremental-build
REM As a work around for following script tries to catch this situation and copys/remanes
REM this tmp-file instead.

REM .SYNOPSIS
REM CopyXmlDocumentation "X:\path\to\source.xml" "Y:\target\dir"

if exist "%~1%" (
  REM if the file exists, copy it as-is
  copy /Y "%~1" "%~2"
) else (
  REM else we try to copy the .tmp file and rename it to the desired target name
  REM we assume that the tmp file is named "vsXXXX.tmp" where XXXX is an arbitrary string
  copy /Y "%~d1\%~p1\vs*.tmp" "%~2\%~n1%~x1"
)