Home > ALM, TFS, TFS2012 > TFS2012: Schedule a One Time Team Build-Approach 2

TFS2012: Schedule a One Time Team Build-Approach 2

In response to the questions asked on MSDN social, I am writing this blog post. The question was “How to schedule a one off build”.


I already blogged approach1 to solve this issue. In this approach, I am building a simple console application that takes three arguments: TFS Team Project Collection URL, Team Project Name and Team Build Definition Name. The console application will then be scheduled through the Windows Task Scheduler. The build definition is manually triggered.

Creating Console Application

Create a new Windows console Application and called TeamBuildQueuer

Add the following assemblies as references




The following is a simple implementation for the Program.cs class. You can make it fancier Smile

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;

namespace TeamBuildQueuer
public class Program
public static void Main(string[] args)
if (args.Length < 3)
Output("Usage TeamBuildQueuer TFSUrl teamProjectName buildDefinitionName");

var tfsUri = args[0];
var teamProjectName = args[1];
var buildDefinitionName = args[2];

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsUri));
if (tfs == null)
Output("Can't find TfsTeamProjectCollection");
IBuildServer buildServer = tfs.GetService<IBuildServer>();

if (buildServer == null)
Output("Can't find build server");

IBuildDefinition buildDefinition = buildServer.GetBuildDefinition(teamProjectName, buildDefinitionName);

if (buildDefinition == null)
Output("Can't find build definition");



private static void Output(string message)

Build the application

Debugging the application

Right click on the project and click on Properties

Click on the Debug tab

Type the three arguments separated by spaces


Run the application

Hit the refresh button if you already have visual studio open. You should see the build is queued


Schedule the Console Application

Find the Task Scheduler application. In Windows 8 I had to search for it from the Start Screen


I named it Queue Build


Specify the date and time for the Task to run at


Keep Start  a program selected


In my case, I am using the following arguments:

http://tfs2012express:8080/tfs/DefaultCollection MyTeamProject TeamBuildActivities

again space seperated


Review and click Finish



This approach is simpler than the previous article I wrote. You don’t need to do any modifications to the build template and you have more flexibility when it comes to scheduling patterns.

  1. May 21, 2013 at 6:46 am

    There’s a command line utility that ships with Visual Studio called TFSBuild.exe to queue builds

    • Lajak Technologies Inc
      May 24, 2013 at 8:58 am

      Cool, I will update the post to reflect that 🙂

  1. January 24, 2013 at 2:27 am

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: