tf.exe on tfspreview

青春壹個敷衍的年華 提交于 2019-11-29 04:41:13

Alright, I am here to tell you that this IS possible without writing your own custom task, using the API, etc... there are a number of articles out here on StackOverflow but the ones with solutions do not appear to work for TFS 2010. I just spent an entire day banging my head against the wall :D

  1. You need to install the MSBuild Community Tasks. Make sure you get the latest version from here: https://github.com/loresoft/msbuildtasks. The latest appears to have been updated and rebuilt against the TFS 2010 assemblies.

  2. You are going to use the MSBuild.Community.Tasks.Tfs.TfsClient task. The reason you are getting that error about not being able to run the executable is because this is an MSBuild ToolTask and you need to pass in the path to the executable as a property (ToolPath) to the task.

  3. The TfsClient task is just a wrapper to tf.exe and the task is missing a lot of possible features for handling the switches in an MSbuild-y way. (and the documentation for this task is nonexistant - i had to look at the code) Luckily I figured out that you can enter all of the command line switches as part of the command itself.

  4. So your final call will look something like this...

    <MSBuild.Community.Tasks.Tfs.TfsClient ToolPath="$(PathToTfTool)"
                                       Command="history /collection:$(TfsProjectCollectionUrl) /stopafter:1 /version:T /format:detailed $(VersionControlPathForBuildWorkspace)"
                                       Recursive="true"
                                       >
    

    <Message Text="TFS ChangeSetNumber: $(ChangesetNumber)" />
    

And after 22 miserable failed builds or builds with no data I finally got... TFS ChangeSetNumber: 41

YAHOO!

Got the command from Martin Woodward: http://www.woodwardweb.com/vsts/determining_the.html MAKE SURE YOU USE THE /DETAILED SWITCH OR IT WONT RETURN THE CHANGESET. I had to look at the code for the task and figure out how it was parsing the output from tf.exe to figure this out.

Code for TfsClient is here for reference: https://github.com/loresoft/msbuildtasks/blob/master/Source/MSBuild.Community.Tasks/Tfs/TfsClient.cs

bherto39

Here's the line of code that worked for me.. after several hours and couple of tries. the difference is that I created an output TaskParameter element within the

Where:

  • ToolPath ="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE" - depends if you're on 32 or 64 bit.

  • $/WorkspacePath name of the path on my workspace, you can view this using tf workspace command

    <MSBuild.Community.Tasks.Tfs.TfsClient ToolPath="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"
                                   Command="history /s:http://tfsserver01:8080/tfs/collectionname /stopafter:1 /version:T /format:detailed $/WorkspacePath"
                                   Recursive="true" >
      <Output TaskParameter="Changeset" PropertyName="ChangesetNumber"/>
    </MSBuild.Community.Tasks.Tfs.TfsClient>
    <Message Text="TFS ChangeSetNumber: $(ChangesetNumber)" />
    

But thanks to this thread

What exactly does the MSBUILD workflow look like? Are you passing this parameter into MSBUILD or is some custom component grabbing this information while MSBUILD is running?

I've come across the class InformationNodeConverters, which has the method GetAssociatedChangesets that takes in an IBuildDetail and returns a List of IChangesetSummary. This would also require that your changesets already be associated before you get to the MSBUILD task. I'll need to check against my TFSPreview instance tonight to see if I can edit the build template, but I would suspect that you should be able to use something like this.

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