如何使用构建后事件签出-复制-签入 TFS 中的文件? [英] How to checkout-copy-checkin a file in TFS using Post-build event?

查看:30
本文介绍了如何使用构建后事件签出-复制-签入 TFS 中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目持有服务器控件.每当我对其进行更改时,我都希望能够在发布模式下构建并将输出 DLL(及其文档 Xml 文件)复制到 Team Foundation Server 中的文件夹中.

I have a Project holding server controls. Whenever I make changes to it I want to be able to Build in Release mode and have the output DLL (and its documentation Xml file) copied to a folder in Team Foundation Server.

我提出了一个构建后事件:

I have come out with a post-build event that:

  1. 检查 DLL 和 XML.
  2. 将它们复制到 TFS 文件夹
  3. 通过一些评论重新检查它们.

这是脚本:

if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkout /lock:none C:\CommonAssemblies\$(TargetFileName)
if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkout /lock:none C:\CommonAssemblies\$(TargetName).xml
if $(ConfigurationName) == Release copy $(TargetDir)$(TargetFileName) C:\CommonAssemblies\ /Y
if $(ConfigurationName) == Release copy $(TargetDir)$(TargetName).xml C:\CommonAssemblies\ /Y
if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkin C:\CommonAssemblies\$(TargetFileName) /noprompt /comment:"File checked in automatically by Post-build action in source project."
if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkin C:\CommonAssemblies\$(TargetName).xml /noprompt /comment:"File checked in automatically by Post-build action in source project."

这有效,但前提是代码至少有一处更改,并且任何 XML 注释至少有一处更改.如果我尝试在没有任何更改的情况下构建两次,我会收到一条错误消息:

This works, but only if there is at least one change in the code, and at least one change in any of the XML comments. If I try to build twice without any change, I get an error saying:

The command "if Release == Re...... " exited with code 1.

我怎样才能摆脱这个错误?

从输出"窗口中,我可以看到 TFS 检测到文件中没有任何更改并撤消编辑.

From the Output window, I can read that TFS detected there were no changes in the file and it Undo the edit.

我可以在我的签入指令中添加什么以在未检测到更改时忽略此类签入?到目前为止,我一直在使用该脚本,但我必须记住每次向代码中添加一个随机空间并添加一些注释以使其正常工作.一定是我遗漏了什么,可能是参数或其他.

What can I add to my checkin instruction to ignore such checkin when no change is detected? I've been working so far with that script, but I must remember each time to add a random space to the code and to some comment for it to work properly. There must be something I'm missing, maybe a parameter or else.

这是输出窗口中的部分文本:

Here's part of the text from the Output window:

C:\CommonAssemblies:
  Controls.dll
C:\CommonAssemblies:
  Controls.xml
          1 file(s) copied.
          1 file(s) copied.
  C:\CommonAssemblies:
  Checking in edit: Controls.dll

  Changeset #6188 checked in.
  C:\CommonAssemblies:
  Checking in edit: Controls.xml

  The following changes were not checked in because the items were not modified.
    Undoing edit: C:\CommonAssemblies\Controls.xml

  There are no remaining changes to check in.

推荐答案

我遇到了 另一个类似的问题,我找到了答案.

I came across another similar question and I found the answer.

/force 参数是签入指令中缺少的.即使其中没​​有检测到更改,这也会检查文件.

The /force parameter is what was missing from the checkin instruction. This checks in the file even when there are no detected changes within.

这个脚本不再抛出错误:

This script is no longer throwing errors:

if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkout /lock:none C:\CommonAssemblies\$(TargetFileName)
if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkout /lock:none C:\CommonAssemblies\$(TargetName).xml
if $(ConfigurationName) == Release copy $(TargetDir)$(TargetFileName) C:\CommonAssemblies\ /Y
if $(ConfigurationName) == Release copy $(TargetDir)$(TargetName).xml C:\CommonAssemblies\ /Y
if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkin C:\CommonAssemblies\$(TargetFileName) /noprompt /force /comment:"File checked in automatically by Post-build action in source project."
if $(ConfigurationName) == Release "$(DevEnvDir)tf" checkin C:\CommonAssemblies\$(TargetName).xml /noprompt /force /comment:"File checked in automatically by Post-build action in source project."

这篇关于如何使用构建后事件签出-复制-签入 TFS 中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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