将 robocopy 与 Visual Studio 2010 生成后和生成前事件一起使用 [英] Using robocopy with Visual Studio 2010 Post-build and Pre-build events

查看:12
本文介绍了将 robocopy 与 Visual Studio 2010 生成后和生成前事件一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Robocopy 在成功时输出 1,这与大多数在成功时以 0 退出的程序不同.Visual Studio(和 MSBUILD)将退出代码 1 解释为错误.

Robocopy outputs 1 upon success, unlike most programs that exit with 0 on success. Visual Studio (and MSBUILD) interprets exit code of 1 as an error.

如何在 Visual Studio 构建后和构建前事件中使用 Robocopy,以便构建环境正确识别其失败和成功?

How can Robocopy be used in Visual Studio post- and pre-build events such that its failure and success are correctly identified by the build environment?

注意:这或多或少是 这篇文章.

Note: this is more or less a repost of this post.

推荐答案

MSBuild extensionpack 包含一个 Robocopy 任务您可以在构建过程中使用.
这可以成为您的解决方案,而不是 VS 构建前/构建后事件吗?

MSBuild extensionpack contains a Robocopy task that you can use in your build process.
Can this be a solution for you instead of VS pre/postbuild events?

如果是这样,您可以扩展 VisualStudio 构建过程,通过覆盖 BeforeBuild、AfterBuild 目标并调用 Robocopy 任务(如果它们更适合您的需求,您也可以覆盖其他目标,请参阅链接的 MSDN 页面中的列表)
所以实际上你应该下载并安装 MSBuild 扩展包,而不是打开项目的 csproj/vbproj 文件并编辑以下方式:

If so, you can extend the Visual Studio Build Process by overriding the BeforeBuild, AfterBuild targets and calling the Robocopy task (you can override other targets as well if they would suit your needs better, see the list in the linked MSDN page)
So actually you should download and install MSBuild extensionpack than open your project's csproj/vbproj file and edit the following way:

为导入 MSBuild 扩展包的 Robocopy 任务添加以下条目

<PropertyGroup>
    <TPath>$(MSBuildExtensionsPath32)ExtensionPack4.0MSBuild.ExtensionPack.tasks</TPath>        
</PropertyGroup>
<Import Project="$(TPath)"/>

覆盖 BeforeBuild、AfterBuild 并执行 Robocopy 任务

<Target Name="BeforeBuild">
<Message Text="Beforebuild" />
  <MSBuild.ExtensionPack.FileSystem.RoboCopy Source="C:	emp
obo_src1" Destination="C:	emp
obo_dest1" Files="*.*" Options="/MIR">
      <Output TaskParameter="ExitCode" PropertyName="Exit" />
      <Output TaskParameter="ReturnCode" PropertyName="Return" />
  </MSBuild.ExtensionPack.FileSystem.RoboCopy>
  <Message Text="ExitCode = $(Exit)"/>
  <Message Text="ReturnCode = $(Return)"/>
</Target>
<Target Name="AfterBuild">
  <MSBuild.ExtensionPack.FileSystem.RoboCopy Source="C:	emp
obo_src2" Destination="C:	emp
obo_dest2" Files="*.*" Options="/MIR">
      <Output TaskParameter="ExitCode" PropertyName="Exit" />
      <Output TaskParameter="ReturnCode" PropertyName="Return" />
  </MSBuild.ExtensionPack.FileSystem.RoboCopy>
  <Message Text="ExitCode = $(Exit)"/>
  <Message Text="ReturnCode = $(Return)"/>
</Target>

这篇关于将 robocopy 与 Visual Studio 2010 生成后和生成前事件一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆