Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XML

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

4.83/5 (29 votes)
15 Mar 2010CPOL3 min read 1   537  
Generate automated builds for source code from multiple branches using Team Foundation Server and Team Builds

Introduction

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

Background

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:

P01_-_Copy.jpg

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.

P02.jpg

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?
Yes...

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

Consider this build definition.

P03_-_Copy.jpg

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’
option.

P04_-_Copy.jpg

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.

P05_-_Copy.jpg

Click on ”Branch’ Button.

P06.jpg

You can compare the TFS before and after branching.

Before branching:

P07_-_Copy.jpg

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

P08_-_Copy.jpg

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.

P09.jpg

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.

History

  • 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.

License

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