Merge Sign
Merge? No Problem!

By default, a Team Foundation Server (TFS) Team Project will have multiple check-out enabled. This means that the same file can be checked-out by more than one individual at the same time. This is actually a good thing in that blocking changes does not occur when different people need to access a file and one or more people are unavailable to undo their check-out.

Some people then get concerned with merge complications (a.k.a. merge hell). At the surface, merging may seem complex, but when broken down it should be fairly straightforward. The built in tool with Visual Studio for compare/merge and third party tools, like KDiff3 and WinMerge, all provide a great way to automatically detect changes in a file. Most of the time those changes are not on the same line and the merge is automatically handled. In the case where two or more people are changing the same line, method or functional piece of code, I would consider that it really isn’t a problem with merging. The team members need to find out why two people are working on the same thing.

Sometimes it may be that two different people recognized the same bug and fixed it. They may both see convoluted code and refactor it to be cleaner. In these types of situations the second person checking in that then sees a merge conflict should be able to easily identify what happened and either throw away their changes or overwrite the previous check-in. In the strictest sense, one could argue that the developer should open a bug and add it to the backlog, but the case of refactoring smelly code doesn’t really fit that model. Often times I will see sprints with a refactoring bucket and task, which means tracking this type of change isn’t easily predictable. Either way, these aren’t major areas of merge complications.

There are times where merging is not that simple, but I would argue that it’s usually a project management issue or an architectural issue at that point. Two people shouldn’t be actively developing the same feature, because that would mean there is a communication breakdown. In an agile environment, the team members should be communicating at least once a day and be aware of what others are working on completing. If the file in question contains so much code that multiple people are inadvertently effecting each other, the code may need to be refactored on a larger scale to remove tight coupling. It should follow a separation of concerns approach.

Conclusion

I find allowing multiple check outs to be more beneficial than not. When Alice forgets to undo a check-out before she leaves for the day and Bob needs to update some other portion of the file, he inevitably ends up with a couple choices that all reduce his productiveness. He can move on to something else, forcing a context-switch in which he’ll have to return to when the file is available. He could find an administrator and have Alice’s check-out undone, which would leave Alice to handle a merge situation anyway with her local changes and whatever Bob checks in. Worst of all, Bob could have no other work to do and he ends up doing nothing productive.

Requirements:

A Visual Studio 2008 edition that supports Team Foundation Server.

Creating a Build Agent:

Start out by opening the Team Explorer window, which can be done by navigating through the menu View –> Team Explorer.  A list of solutions may appear, but if not, click on the icon highlighted in the image below and select the Team Portal project as appropriate.

Team Explorer Builds

Expand the Builds folder that is one level deep within the Team Portal project.  Upon right clicking on the Builds folder, the following menu will be displayed.  The starting point is Build Agents, so click on Manage Build Agents.

Right Click on Builds Folder

A new window will appear that allows the creation of new and editing of existing build agents.

Manage Build Agents Window

After clicking New, a popup window displays asking for the properties and configuration to create the new build agent.  The default values are shown below.

  1. Fill out a display name for the build agent.  This build agent can be used with multiple build definitions, as will be shown below.
  2. Enter the name of the build server.
  3. Optionally change working directory to be used on the build server.  Using a shared location on the build server can be useful for team members to troubleshoot.

Build Agent Properties

After clicking okay, the newly created build agent should appear in the create and edit screen.

Manage Build Agents Part 2

Creating a Build Definition:

Now that a build agent is created, a build definition needs to be created and associated with the build agent.  In Team Explorer, under the Team Portal directory, right click the builds directory again and click on New Build Definition.

New Build Definition Context Menu

The initial screen shown below is what should be shown, which will allow for entering all of the required information for a build definition.

Build Definition Creation

Enter a verbose name for the build definition.  For the continuous integration build definitions, appending something like “_CI” may be helpful.  If you would like multiple branches to be built separately using continuous integration, appending something like “_Trunk_CI” may be helpful.

Build Definition Name

On the next tab, one or more Source Control Folders may be set up.  The only need for multiple would be in the case that solutions reference other solutions within the TFS structure.  If branching is used, be sure to narrow down the Source Control Folder to the appropriate level.  It may be useful to have all branches handled through a single build definition, but I prefer to have them individually set up.

If you actually select the text within the Source Control Folder, an ellipsis button will appear allowing you to select the appropriate location through a select folder popup.

Build Definition Source Control Folder

On the project file tab, you will see something similar to the following.  It should automatically populate the version control folder using the information previously provided, but it will warn about needing to actually create the file.  Click the create button, which will add the folder TeamBuildTypes at the root level of Team Portal and create the necessary MSBuild files.  Note that these files and folders are added to source control.  The next few screen shots will walk through the creation process for the MSBuild project.

Build Definition Project File

If the Source Control Folder you entered contains more than one solution file, you will see a list of all available solutions to build.  Select all that you want to build as part of this build definition.

MSBuild Project File Solutions

Under the configurations tab, select all of the target configuration you want to build during this build definition.  For example, Release, Debug, Staging, etc. and any Platform combinations that may be appropriate.

MSBuild Project Configurations

Within the Options tab, you can set up which automated tests are to be executed and if code analysis should be run.  Note that in order for these to run on the build server, Visual Studio must be installed, as the MSTest framework and Code Analysis settings are not part of TFS.

MSBuild Project Options

After clicking Finish, we are brought back to the build definition window and the warning should be replaced with the message “Found MSBuild project file”.

Build Definition Version Control Folder

In the source control explorer window, you should now see newly created MSBuild folder directory beneath the top level Team Portal folder.

Source Control Explorer TeamBuildTypes

A list of files within the directory show that the wizard created two files.  The *.rsp is not in a human readable format, but the *.proj file is the MSBuild XML file that may be of interest for customization at a later point.

Detailed TeamBuildTypes

The next tab in the build definition creation is for setting up how long each type of build result should be kept.  By kept, it means storing the full source, test results, code analysis and anything other that may be part of the build process.  The only real concern here is disk space on the build server.  Remember that if you have many solutions using continuous integration on the build server this may become an issue.  It may take an extra step or two, but since the code is always stored in TFS, you can rebuild from any point in history.

Build Definition Retentions

The next tab is how the build definition and previously created build agent are tied together.  Select the build agent from the drop down menu.  The new button will allow you to create a build agent as part of the build definition creation process, but for the sake of this post, I’ve separated the two.  The text entry area is asking for the place to copy the output from the build process.  Generally, I leave it on the build server, but any network location will work.  If you refer back to the folder location I used for the build definition’s working folder, you can see I’ve created a share on the build server called “builds”.  Within the builds directory are two sub-directories, “completed” and “working”.  The working folder is where each build agent executes the assigned build definitions.  The completed folder is where the output from the build definition is copied.  Within each of the sub-directories, I have folders that match the build definition.  The output created from the build definition automatically is contained in a generated folder name that includes a timestamp, so there is no worry of things getting overwritten.

Build Definition Defaults

The last tab in creating a build definition is to specify how the build will be triggered.  You can have it as a manual process, after each check-in or accumulated check-ins, or even specify specific recurrence patterns like a nightly build.

Build Definitions Triggers

Managing Alerts:

From the Team drop down menu, select Project Alerts.

Manage Alerts Team DropDown

The following window will then allow selecting which types of alerts you would like to receive.  By default, the email address and HTML format are already populated.

Project Alerts

For full control over the alerts, go to the Team drop down menu and select Alerts Editor.

Alerts Editor Context Menu

The following tabbed window will open and allow for full customization and creation of alerts.  As shown, you can create combinations using AND and OR criteria in the alerts definition.

Alerts Editor

Testing the new Build Definition and Build Agent:

Going back to the Team Explorer window and within the Team Portal –> Builds directory, right click on the newly created build definition.  Then click Queue New Build.

Queue Build Context Menu

The Queue Build window should appear.  No changes should be required.  Just click “Queue”.

Queue Build Window

After clicking “Queue”, the Build Explorer tabbed window should be open.  This window allows for filtering by build definition, status and agent.

  • Red ‘X’ = Failed
  • White circle with a Green Arrow = In Progress
  • Three white overlapping squares = Queued
  • Green Check = Success

The Build Explorer window has two tabs that can be navigated to at the bottom.  Once builds are finished, the are automatically removed from the Queued tab and moved to the Completed tab.

Build Explorer

By double-clicking on the build line entry, the details will be opened in a new tabbed window.  From here, access to the log can be found through the linked file located in the targeted drop location.  The full BuildLog.txt can be quite large.

Build Details

The Release.txt is usually much smaller and can be found by expanded the Result details and clicking the Release.txt link.

Build Details Part 2 build_34

Thoughts:

A lot of customization can be applied to the build process.  I’ve found the following book very helpful.

Book: Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build (PRO-Developer) Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build (PRO-Developer)

If you’re wondering why your Visual Studio may have less options than in some of my screen shots, it may be because I have the Visual Studio Team System 2008 Team Foundation Server Power Tools – October 2008 Release installed.  That install is not required for the purpose of this post.