Click here to Skip to main content
13,554,936 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


50 bookmarked
Posted 1 Mar 2010
Licenced CPOL

Generate Automated Builds for Source Code from Multiple Branches using Team Foundation Server and Team Builds

, 14 Mar 2010
Rate this:
Please Sign up or sign in to vote.
Generate automated builds for source code from multiple branches using Team Foundation Server and Team Builds


This article demonstrates how to generate automated builds for source code from multiple branches using Team Foundation Server and Team Builds.


I work for a project where multiple branches of the source code are maintained for various reasons:

  • Customizations of the product for particular customers
  • Hot fixes for the previous releases of the product

We have the TFS structure:


Problem Statement

  • Code changes are done in the hot fix branches and later merged into the main branch after testing.
  • Compiling source code for multiple branches and generating respective Setups on a regular basis.
  • Continuous builds for various modules of the project which will be queued immediately after a developer checks in the code. Nightly builds generate the setup for multiple branches.


Basic Idea

We decided to automate this using Team Foundation Server and Team Builds.

Is it possible to write a build definition for one branch and reuse it for multiple branches?

To reuse build definitions for multiple branches, we have to follow some coding standards in build definitions.

Consider this build definition.


In the above code, we used variables to hold the branch name, project name, etc. By doing so, we can reuse the same build definition template for multiple branches.

  • To make it easier, we have developed Addin's in Visual Studio. We can branch the code and generate build definitions for the branch automatically.
  • In the Addins, we have written TFS custom tasks to generate build definitions for a particular branch.

Using the Code (Visual Studio Add In)

The source code for the AddIn is uploaded here. For ease of use, I have created an MSI setup for the AddIn. Here are the steps for using the Branching AddIn.

Step 1: Download the code, compile and Install the Addin.

Step 2: After successful install, open Visual Studio. Right click on the TFS Project you want to branch. You can see the Addin in the Team Explorer tree. Click on ’Branch for sprint’


Step 3: Source - Select the Team Project and the source path you want to branch from the tree.
Target - Select the Path in the tree where you want to branch to. Enter the branch name.


Click on ”Branch’ Button.


You can compare the TFS before and after branching.

Before branching:


After Branching: Source code is branched and new build definitions are created for the new branch:


Step 5: Clean up the old branches. Right click on the branch you want to clean up. Click on ’Clean’ button. This will clean the remove the builds and the source code from the branch.


Key Words

For those who are new to TFS, here are some one liners:

Team Foundation Server (TFS)

  • Microsoft product which offers source control, data collection, reporting, and project tracking
  • Intended for collaborative software development projects
  • Available either as stand-alone software, or as the server side back end platform for Visual Studio Team System (VSTS)

Team Build

  • Build server included with TFS
  • Can be used by developers to do a complete build of the most recent versions of the software contained in source control
  • Analyzes what changes have been made to in source control since the last successful build
  • Updates any work items to indicate that progress has been made
  • E.g.: If a tester filed a bug work-item against build #17, and a developer checked in a change just prior to build #18 being created, then the bug work-item would be updated to state that the bug has been fixed.
  • TFSBuild.proj is the file which drives a Team Build. The Team Build Language is synonymous with the Microsoft build language.


  • 25th Feb, 2010: This is the first draft of the application. I will try and update this with some more features.

About Proteans Software Solutions

Proteans, a CAMO group company, is an outsourcing company focusing on software product development and business application development on Microsoft Technology Platform. "Committed to consistently deliver high-quality software products and services through continual improvement of our knowledge and practices focused on increased customer satisfaction.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
I am currently working in an outsourced software product development company, PROTEANS SOFTWARE SOLUTIONS LTD.( as a Module Lead.

You may also be interested in...


Comments and Discussions

Questionvdproj not supported in Visual Studios 2012 Pin
Arelowo Alao27-Oct-13 11:49
memberArelowo Alao27-Oct-13 11:49 
QuestionVS 2010 - TFS API 2010 obsolete method Pin
syynapse24-Oct-11 4:25
membersyynapse24-Oct-11 4:25 
GeneralNice Tool Pin
kthiyag26-May-10 14:48
memberkthiyag26-May-10 14:48 
GeneralRe: Nice Tool Pin
SureshGubba26-May-10 19:50
memberSureshGubba26-May-10 19:50 
GeneralRe: Nice Tool Pin
kthiyag27-May-10 8:25
memberkthiyag27-May-10 8:25 
GeneralNice article... :) Pin
saravanansm8-Mar-10 22:36
membersaravanansm8-Mar-10 22:36 
Generalwell done.. congrats for making such a wonderful article.. Pin
Thajuddeen2-Mar-10 4:07
memberThajuddeen2-Mar-10 4:07 
GeneralGood work Pin
avi511-Mar-10 21:12
memberavi511-Mar-10 21:12 
Generalgood work on build script Pin
shailendra.singh19841-Mar-10 20:55
membershailendra.singh19841-Mar-10 20:55 
GeneralThis is interesting one Pin
san_vetakari1-Mar-10 20:55
membersan_vetakari1-Mar-10 20:55 
GeneralGreat article :) Pin
Anil_Saran1-Mar-10 20:36
memberAnil_Saran1-Mar-10 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 15 Mar 2010
Article Copyright 2010 by SureshGubba
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid