Customizing and Extending Team Foundation Build


Team Foundation Build provides out-of-the-box capabilities for creating basic build types. But, what if you have special needs during the build - for example, you have to trigger a third-party testing tool during the build process? These scenarios are not uncommon - therefore it is important to understand how Team Foundation Build can be extended and customized. There are also some limitations that you should understand.

Team Foundation Build is built upon MSBuild, therefore most (if not all) of the limitations that apply to MSBuild also apply to Team Foundation Build. For example, Team Foundation Build is primarily designed for building .NET Framework 2.0 applications. If you want to build anything else, you have to customize the build process.

Team Foundation Build does not support deployment projects. (However, it does support the Web deployment project.) Out-of-the-box, you have no user interface to modify the build scripts

Important

Although there are no prebuilt tools to modify Team Foundation Build scripts, there are a few really interesting projects on the Web. The first is a Windows Presentation Foundation sample in the Windows SDK called GUI for MSBuild. You can download the sample at http://windowssdk.msdn.microsoft.com/en-us/library/ms756489.aspx. There is also another free tool called the MSBuild Sidekick that you download at http://www.attrice.info/msbuild/.

In the current version of Team Foundation Build, you have to manually check out the TfsBuild.proj file, edit the XML, and then check back in the file. Team Foundation Build does not contain built-in extensions such as continuous integration, rolling build, and gauntlet (a build configuration in use at Microsoft). There are also no built-in management capabilities - you can't just dynamically select a build machine and automatically prepare it. Team Foundation Build also doesn't support build queuing or requests.

Important

If you want to track the progress of your builds on your desktop, you can download a Team Foundation Build Notification tool. The notifications are very similar to the e-mail notifications that appear at the bottom right of your screen when you receive mail in Outlook 2003. You can download the tool and source code at http://blogs.msdn.com/abhinaba/archive/2006/08/09/293234.aspx.

What exactly does this mean? There are tons of opportunities for developers to build on (forgive the pun) the Team Foundation Build platform. The Team Foundation Build API is well documented within the Visual Studio 2005 SDK and provides opportunities to trigger and configure your builds in really interesting ways. You can download the Visual Studio 2005 SDK at: http://msdn.microsoft.com/vstudio/extend/.

Existing Build Tasks

There may be circumstances where you will need to FTP files to another directory, create your own custom clean build, run third-party tools, and so forth. Fortunately, there is a vibrant development community around MSBuild tasks. Here are the two primary resources:

  • MSBuild Tasks on Tigris.org: This is an open-source effort to compile different MSBuild tasks. You can access the forums for help in implementing the tasks (http://msbuildtasks.com), or you can download the binaries at http://msbuildtasks.tigris.org.

  • Microsoft Services (UK) Enterprise Solutions Build Framework (SBF): This is a list of over a hundred useful MSBuild tasks compiled by Microsoft Services UK. You can download them from GotDotNet at gotdotnet.com/codegallery/codegallery.aspx?id=.

The MSBuild EXEC task allows you to run external applications with specific arguments. You can use the following parameters along with this task: Command, ExitCode, IgnoreExitCode, WorkingDirectory, and so forth.

Custom Build Tasks

Within your basic build type, you can incorporate custom build tasks that trigger any functionality that you want. The UsingTask element points to an assembly (which is usually located somewhere on your build server). The following build task adds information into the build log. You can use the same template to make the build server do pretty much anything. Here are the required steps to create a custom build task:

  1. Launch Visual Studio 2005 Team Suite and select FileNewProject.

  2. Select the C# Class Project type and name the project CustomBuildTask.

  3. Once the project loads in Solution Explorer, rename Class1.cs to BuildTask.cs.

  4. Right-click your solution in the Solutions Explorer and select Properties.

  5. Change the assembly name and default namespace to BuildTask.

  6. Close the solution properties.

  7. Right-click the References folder.

  8. Add the following references to your project:

     Microsoft.Build.Framework Microsoft.Build.Utilities 

  9. Edit BuildTask.cs.

  10. Change the source code as follows. Notice the references to Microsoft.Build.Framework and Microsoft.Build.Utilities, The Execute method launches your build task during the build process:

     using System; using System.Collections.Generic; using System.Text; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System.Diagnostics; using System.IO; namespace BuildTask { public class LogMessage : Task { public override bool Execute() { LogMessage(); return true; private void LogMessage() { Log.LogMessage("Hello World"); } } } 

  11. Build your solution.

  12. Save your solution.

  13. Copy the DLL you created (CustomBuildType.dll) to the root of the C:\ drive (or any preferred directory on your build server).

Registering Your Custom Task

Here is how you can register your new task within a preexisting build type:

  1. Open the Source Code Explorer (ViewOther WindowsSource Code Explorer).

  2. Checkout your target build type.

  3. Edit TfsBuild.proj.

  4. Replace </Project> with the following code (substituting <solution path> with the path to the project .dll you built earlier):

     <UsingTask TaskName="BuildTask.LogMessage" AssemblyFile="C:\<solution path>\CustomBuildTask.dll" /> <Target Name="BeforeDropBuild"> <LogMessage SourceDir="$(SolutionRoot)" /> </Target> </Project> 



Professional Team Foundation Server
Professional Team Foundation Server
ISBN: 0471919306
EAN: 2147483647
Year: 2004
Pages: 168

Similar book on Amazon
Professional Team Foundation Server 2010 (Wrox Programmer to Programmer)
Professional Team Foundation Server 2010 (Wrox Programmer to Programmer)
Professional Application Lifecycle Management with Visual Studio 2010 (Wrox Programmer to Programmer)
Professional Application Lifecycle Management with Visual Studio 2010 (Wrox Programmer to Programmer)
Professional Scrum with Team Foundation Server 2010 (Wrox Programmer to Programmer)
Professional Scrum with Team Foundation Server 2010 (Wrox Programmer to Programmer)
Team Foundation Server 2008 in Action
Team Foundation Server 2008 in Action

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net