使用的Robocopy与Visual Studio 2010年后建造和pre-生成事件 [英] Using robocopy with Visual Studio 2010 Post-build and Pre-build events

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

问题描述

的Robocopy输出1成功后,不像一般程序,用0成功退出。 Visual Studio的(和MSBUILD)间$ P $点退出$ 1 C $ C作为一个错误。

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.

如何使用Robocopy在Visual Studio中和后的pre-建设活动中​​使用,例如,它的成功与失败都正确地构建环境确定的?

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?

注:这是或多或少这个帖子

推荐答案

的MSBuild extensionpack 包含的Robocopy任务,你可以在构建过程中使用。结果
可这是你,而不是一个解决方案VS pre / postbuild事件?

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?

如果是这样,你可以扩展可视通过覆盖BeforeBuild,AfterBuild目标和调用任务的Robocopy 的Studio生成过程(你可以覆盖其他的目标,以及他们是否会满足您的需求更好的,请参阅MSDN链接页面列表)结果
所以,其实你应该下载并安装的MSBuild extensionpack比打开您的项目的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 extensionpack的任务的Robocopy

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

重写BeforeBuild,AfterBuild并执行任务的Robocopy

<Target Name="BeforeBuild">
<Message Text="Beforebuild" />
  <MSBuild.ExtensionPack.FileSystem.RoboCopy Source="C:\temp\robo_src1" Destination="C:\temp\robo_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:\temp\robo_src2" Destination="C:\temp\robo_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年后建造和pre-生成事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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