开发者

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 c开发者_如何学编程urrent branch in the Build Number field (or a more appropriate field) of the assemblies it creates?


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.


The version is easy in terms of getting it and updating the various AssemblyInfo.cs files.

I'd organise your TFS structure in a similar way to the Subversion conventions, so have a trunk, tags and branches folder.

Through consistent naming you can make sure that your specific MSBuild file is always a set number of directories down from either the trunk of from a specific branch name.

Have a custom MSBuild task that works this out for you (by navigating up the TFS folder hierarchy), and feed this into your property that is used to update the AssemblyInformationalAttribute. You can use the FileUpdate task from http://msbuildtasks.tigris.org/ to perform a Regex replace on your AssemblyInfo.cs files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜