Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS Build: include branch name in "build number" field of assemblies

I'd like to be able to look at an assembly and quickly identify which branch it was built out of.

What's the best way to cofigure TFS Build to include the name of the current branch in the Build Number field (or a more appropriate field) of the assemblies it creates?

like image 487
Robert Levy Avatar asked Jan 20 '11 00:01

Robert Levy


1 Answers

Have a look at the Version Task in http://msbuildtasks.tigris.org/

It will enable you to update the assemblyinfo.cs on build.

That still leaves the "how" to identify the branch...

On the risk of having a religious debate on version numbering you can dedicate one part of the major.minor.build.revision part to the branch. For example, major.minor just follows your 'outside/commercial' version number, build is the buildnumber form TFS and revision 1 indicates your main branch, revision 2 indicates a certain branch. You can also use on of the other assembly version attributes, like AssemblyInformationalAttribute to store an branch id in it.

I'm not complete up-to-date how you can detect the branch you're on but worst case that is just a matter of getting the current-directory and apply some logic to infer the branch-name. The output of a tf branch . command should also give you the branch name for a current workspace but you'll need a custom task to extract only the first line.

Not a plug-and-play answer but it might bring you in the right direction.

like image 69
rene Avatar answered Nov 08 '22 06:11

rene