Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

msbuild - tf.exe on tfspreview

I need to get the ChangeSetId in tfspreview for our continuous integration. I just need this single number nothing else. I tried all possible MSBuild tasks that I could find, but there is always another smaller issue stopping me.

For MSBuild.ExtensionPack.Tfs.TeamBuild I get :

Could not load file or assembly 'Microsoft.TeamFoundation.Client, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

and for TfsClient -task in community-pack (which is generating following exec: tf.exe history . /StopAfter:1 /noprompt /format:detailed /recursive) I get:

The specified task executable could not be run. The system cannot find the file specified

My question is; Is it possible to execute TF.exe on tfspreview server? or can I get the assembly Microsoft.TeamFoundation.Client on the build server to execute one of these two tasks?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...