SIGN UP MEMBER LOGIN:    
ARTICLE

How to Work With TFS - TFS Build Agent, Build Definition, TFS Build Custom Task

Posted by Surya Prakash Articles | .NET 4.5 October 31, 2011
In this article we will see how to create a TFS build Custom task.
Reader Level:

In this example, I want to execute my own custom task which will write some text into the event viewer as "My Custom Task is executed" & this custom task has to be executed after the TFS build succeeds

To proceed on we have to handle the below step:

  1. Create class library to handle "Custom Task"
  2. Create "TFS Build Agent"
  3. Create "New Build definition"
  4. Run TFS build

Step 1 : Custom Task

Writes text into event viewer after TFS build succeeds. This is to be implemented in Class Library.

  1. First create a Class Library & name it as "MySample"
  2. Add a class called MyTask and add flowing reference to the library
    • Microsoft.Build.Framework;
    • Microsoft.Build.Utilities;
    • System.Diagnostics;
  3. Now inherit the class "TASK" as shown below

public class MyTask : Task
{
    public override bool Execute()
    {
        EventLog log = new EventLog();
        log.Source = "Application";
        log.WriteEntry("Step 2 Executed");
        return true;
    }

}

Note: In the above code, we are overriding the execute method & implementing our own implementation.

  1. Now compile it and as usual it will generate MySample.dll

Step 2 : Create a TFS Build Agent:

Before working on a TFS build definition we need to have a TFS build agent.

Let's follow below steps to create a build agent

  1. Connect to TFS Server from Team Explorer
  2. Right click on Build folder & select "Manage Build Agent"

    TFS

  3. Now click on the "New" button in the build agent window & provide the below necessary information

    TFS agent

Display Name: Name of your choice

Computer Name: TFS Server name

Communications port: TFS server port

Working directory: TFS build will create build files at this location. So provide the path of the TFS server's physical path

Agent Status: Enabled

  1. Now Click "Ok" button

Step 3 :Create TFS Build Definition:

  1. Connect to TFS Server from Team Explorer
  2. Right click on Build folder & select "New Build Definition"

    TFS in .NET

  3. A new window will open up as shown below

    .NET TFS

General - Build definition name: Enter build definition name

  1. Select workspace

    workspace in TFS

Status: Active

Source Control Folder: TFS server path project

  1. Select "Project file", click create button

    TFS project title

  2. MS Build Project file creation wizard will open up. In this select the item as shown below

    project title in TFS

  3. Click next and leave other options as is & click the FINISH button.
  4. Leave retention policy section as it is

    retention policy in TFS

  5. Now select Build Defaults

Build Agent: Should select build agent name that we have created in Step 2 Create TFS Build Agent

Builds will be staged: should provide shared path which TFS server has access

  1. Trigger section allows to configure TFS build to run at those intervals
  2. Finally click ok button

Step 4 : Run TFS Build

  1. Connect to TFS Server from Team Explorer
  2. Expand Build folder & right build definition name which you want to run. In our case right click "MyTestBuildDefinition" & select Queue new build definition

    Expand Build folder in TFS

  3. Select as shown below
    • Build Definition name
    • Build Agent name
    • Drop folder
    • Priority

    TFS

Now by this time, build definition would be stated up & know the processing right click on build definition name & select open

team foundation server

Finally you should be seeing build succeeded if everything goes fine & now go the path (entered while creating build definition & build agent) to see the build files.

Happy coding, Hope this helps!

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor