Command-line interface

Team Foundation Build's command-line functionality is useful for a variety of reasons. It enables you to automatically schedule tasks and administer builds from remote locations. If you are planning to create a build lab, the Team Foundation Build command-line tools will greatly simplify the tasks of managing multiple build servers (rather than manually drilling into each machine using, for example, Terminal Services).

The Windows command console supports a variety of DOS-like commands — for example, md (to create a directory), rd (to remove a directory), and dir (to view a directory listing). To view a list of all the available options for a particular command, simply use the /? or /help option.

To work and operate Team Foundation Build, you would use the command-line tfsbuild executable (tfsbuild.exe).

Starting a build

To start a build, simply use the following syntax (described in the following list):

      tfsbuild start Teamfoundationserver TeamProject BuildType [/m:buildmachine] [/b:builddirectory] 

  • Teamfoundationserver is the server URL on which the solutions being built are checked in.

  • TeamProject is the name of the target Team Project.

  • BuildType is the build type to be used for the build.

  • /m (machine):buildmachine is the machine on which the solutions need to be built. By default, the build machine provided in the build type would be used.

  • /b (builddirectory):builddirectory is the directory in which the build process takes place. By default, the build directory specified in the build type would be used.

Here is an example:

     tfsbuild start http://TestTFS:8080 TestTeamProject1 BetaBuildType /m:BuildServer1     /b:C:\build\ 

Deleting a build

To delete a build, use the following syntax (described in the following list):

      tfsbuild delete Teamfoundationserver TeamProject BuildNumbers [/noprompt] 

  • Teamfoundationserver is the server URL on which the solutions being built are checked in.

  • TeamProject is the name of the target Team Project.

  • BuildNumbers are the builds that need to be deleted. Multiple build numbers can be provided, delimited by space.

  • [/noprompt] means do not prompt while deleting the build(s).

Here is an example:

      tfsbuild delete http://TestTFS:8080 TestTeamProject1 MyBuild_20051027.1 20051027.2 

Stopping a build

To stop a build, use the following syntax (described in the following list):

      tfsbuild Stop Teamfoundationserver TeamProject BuildNumber [/noprompt] 

  • Teamfoundationserver is the server URL on which the solutions being built are checked in.

  • TeamProject is the name of the target Team Project.

  • BuildNumber is the build to be stopped. If the build number has spaces, this needs to be provided within single quotes.

  • [/noprompt] means do not prompt while stopping the build.

Here is an example:

      tfsbuild stop http://TestTFS:8080 TestTeamProject1 MyBuild_20051027.3 


If the server with your drop directory runs out of space, your build will automatically stop.

Setting up a nightly build

There is only one way to configure recurring builds: using the Windows scheduler. With this method, you can configure your build schedule with a high level of granularity; it could be a weekly or daily build or you can set up an hourly build if need be. You can also group together build operations.

To schedule your builds, you can use the Schedule Tasks tool (SCHTASKS.EXE) which is a command-line version of the standard graphical Task Scheduler available by clicking Start image from book Accessories image from book System Tools image from book Scheduled Tasks. Don't use the Schedule Service Command Line Interface (AT.EXE). It's not very configurable and lacks the capability to remotely administer tasks (unlike SCHTASKS).

To configure a recurring (or nightly) build, follow these steps:

  1. Log into your build server. Create a new blank document using Notepad.

  2. Paste the build commands you want to execute (see the preceding section for more information). Please make sure that your drop directory folder and permissions have been preconfigured. Here is an example of the build commands you would write out in your batch file:

          tfsbuild start http://TestTFS:8080 TestTeamProject1 BetaBuildType /m:BuildServer1 /b:C:\build\</para> 

  3. 3. Click File image from book Save As. Select a name and location for your file (preferably in a location where it can only be accessed by an Administrator and the Team Foundation Build Service). Save the file using the .bat extension and make sure you set the Save As Type field to All Files.

  4. Open the Control Panel (by clicking Start image from book Control Panel). Double-click the Scheduled Tasks icon.

  5. Click the Add Scheduled Task option. The Scheduled Task Wizard will appear. Click Next.

  6. Click the Browse button and select the custom batch file you created.

  7. Name your task (for example, Nightly Build) and select the frequency with which it should occur. The available options include Daily, Weekly, Monthly, One Time Only, When My Computer Starts, and When I Log On. Select the option appropriate for your project requirements (for example, a nightly build would require the Daily option).

  8. Set the time when the build commands should be executed and on what date the process should start.

  9. Select an account with the proper credentials to run a build on the machine. You can set the credentials for the task by typing in the username and password. The account you select should have the Team Foundation Server "Start a build" rights to start a build operation. Otherwise, you will not be able to run the build and build commands.

  10. Click Next to complete the task configuration process.

You can then view all of your nightly builds using the command-line Task Scheduler SCHTASKS. To view all the build tasks that are scheduled using SCHTASKS, simply type the following in the command-line window:


You will be provided with the task name, the next run time, and the status. SCHTASKS comes with a variety of commands to launch scheduled tasks on demand. For example, to immediately run a scheduled task, use the Run command by specifying the Task Name (/TN). For example:

      schtasks Run /TN "Nightly Build" 

You can specify the credentials of the person who wants to launch the build (using SCHTASKS) by using the Username (/u) and Password (/p) options. For example:

       schtasks Run /u: BuildAccount /p: $crB1dP$$wd! /TN "Alpha Build" 

Continuous integration (CI)

Microsoft (and many other software development shops) build their products on a daily (or nightly) basis. One of the core principles of SCRUM is "Build early, build often." If you are a practitioner of an Agile methodology, a daily build might not be good enough. Your iterative process may be a lot shorter than that. You may also want to build several times a day (logically, whenever you check in your source code or whenever it has changed).

Continuous integration (CI), a term derived from Extreme Programming, is the implementation of "Build early, build often." By automating your build process as much as possible, integration bugs are found faster and more often. You can also pinpoint compatibility problems. If you incorporate solid testing practices in your build process, your code will be more robust and you'll experience teamwide efficiency gains. Think about it: If you have dozens of developers working on a section of code and it's not well integrated, then you will experience a lot of problems when you try to merge your code. For definitive information about CI, please refer to Martin Fowler and Matthew Foemmel's article at

Unfortunately, Team Foundation Build has no built-in support for continuous integration. Using techniques similar to scheduling tasks shown in the preceding section, you can implement CI in your own environment. Khushboo Sharan has posted information and code on implementing continuous integration on her weblog. Visit

You can also refer to a Continuous Integration white paper on MSDN available at

Professional Visual Studio 2005 Team System
Professional Visual Studio 2005 Team System (Programmer to Programmer)
ISBN: 0764584367
EAN: 2147483647
Year: N/A
Pages: 220 © 2008-2017.
If you may any questions please contact us: