TFS 2010 Queue New Build Workflow Activity


This has helped me a couple of times, so thought I’d post it. It’s a C# workflow activity that you can incorporate into your TFS 2010 build workflow to queue one build definition from another, i.e. when you’re queueing buddy builds. I’ve used this when I have a single build definition that does a get and compile, and with a second build definition that simply packages the solution ready for deployment.

FYI: The package build definition is very generic, and not tied to a single piece of work, hence splitting it apart from the initial Continuous Integration build definition.

The assumption is that target build definition is in the same TeamProject and TeamCollection as the primary build definition.

using System;
using System.Activities;
using System.Diagnostics;
using System.IO;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Build.Client;

namespace BuildTasks.Activities
// Queue a new build from the same Team Project.
// Change this class if you wish to use a different team project.
public sealed class QueueNewBuild : CodeActivity
// The Team Project that the build definition belongs to.
public InArgument<IBuildDetail> BuildDetail { get; set; }

// The build definition to queue
public InArgument<String> BuildDefinition { get; set; }

protected override void Execute(CodeActivityContext context)

// Obtain the runtime value of the input arguments
string buildDefinition = context.GetValue(this.BuildDefinition);
IBuildDetail buildDetail = context.GetValue(this.BuildDetail);

var workspace = buildDetail.BuildDefinition.Workspace;

// Obtain the Team Project for the current build definition.
string tfsProject = buildDetail.BuildDefinition.TeamProject;

string configurationServerUri = buildDetail.BuildServer.TeamProjectCollection.Uri.ToString();

TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri(configurationServerUri));
IBuildServer buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));
IBuildDefinition buildDef = buildServer.GetBuildDefinition(tfsProject, buildDefinition);




About jpadda

Technical Consultant currently working as part of the .Net team for EMC Consulting.
This entry was posted in Team Foundation Server 2010. Bookmark the permalink.

2 Responses to TFS 2010 Queue New Build Workflow Activity

  1. Hi Jag,

    great post. This is the sort of thing that I am looking at doing for our build environment.

    Having recently started dealing with this, could you explain how to use the code that you have pasted? I am guessing somewhere in my xaml file, but I don’t know that yet.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s