Build Customization and Extensibility

As you start using the product, you'll quickly realize that Team Foundation Build will not necessarily cover all of your build scenarios right out of the box. Team Foundation Build runs through an established process. If you need to add extra steps in the build process (or even change the order of the steps), you can, simply by editing XML files and changing existing properties. Other customization scenarios include specific build numbering or naming requirements or introducing an extra step to obfuscate your executables. Because MSBuild is at the core of the engine, customization is made quite a bit simpler. Some of the reasons you might want to customize a build include integrating a third-party product or shaping the build process to comply with a standards body (such as Sarbanes-Oxley or ISO). Figure 23-10 shows how build configuration event files can be edited in Visual Studio 2005.

image from book
Figure 23-10

Creating MSBuild tasks

You can programmatically create a custom MSBuild task using a bit of code. First of all, you must import two namespaces: Microsoft.Build. Framework and Microsoft.Build.Utilities:

     using System;     using Microsoft.Build.Framework;     using Microsoft.Build.Utilities; 

Then you can derive the Microsoft.Build.Utilities.Task class. We created a new class called customTask that derives from Task as the framework for our new MSBuild task:

     namespace MyTasks     {      public class customTask : Task        { 

We then created a method called Execute, which returns a value of true:

            public override bool Execute()            {                return true;            } 

Then we created a custom property aptly called customProperty. You can define one or many of these properties for each MSBuild task. As you can see, we've added the ubiquitous get/set options:

         private string customProperty;         public string customProperty         {             get { return customProperty; }             set { customProperty = value; }         }     } } 

Once you compile the task, you can access it in your MSBuild targets. Here is what our custom task would look like in an MSBuild target file:

    <Project xmlns="">       <Target Name="customTarget">         <customTask customProperty="Value123" />       </Target>    </Project> 

In order to use a custom MSBuild task, you must first register your task in your target. You can do this by using the UsingTask node to reference your custom task name and assembly:

      <UsingTask TaskName="customTask" AssemblyName="customTask.dll" Condition="" /> 

For more information about creating custom MSBuild tasks, please refer to the MSDN documentation.

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: