How to checkout-copy-checkin a file in TFS using Post-build event?

回眸只為那壹抹淺笑 提交于 2019-12-21 06:23:11

问题


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. Checks both DLL and XML out.
  2. Copies them to the TFS folder
  3. Checks them back in with some comments.

This is the script:

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."

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.

How can I get rid of this error?

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.

回答1:


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

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."


来源:https://stackoverflow.com/questions/13711153/how-to-checkout-copy-checkin-a-file-in-tfs-using-post-build-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!