Click here to Skip to main content
13,598,829 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


21 bookmarked
Posted 30 Oct 2011
Licenced CPOL

How to Work with TFS

Rate this:
Please Sign up or sign in to vote.
TFS Build agent, Build definition, TFS Build Custom Task


In this article, we will see how to create TFS build Custom task.

In this example, I want to execute my own custom task which will write some text into event viewer as “My Custom Task is executed” & this custom task has to be executed after 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 Class Library & name it as “MySample
  2. Add a class called MyTask and add the following references to the library:
    1. Microsoft.Build.Framework
    2. Microsoft.Build.Utilities
    3. 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 execute method & implementing our own implementation.

  4. Now compile it and as usual, it will generate MySample.dll.

Step 2 – Create TFS Build Agent

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

Let’s follow the 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”.


  3. Now click on “New” button in build agent window & provide below necessary information:


    • Display 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 path of TFS server physical path
    • Agent Status: Enabled
  4. 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”


  3. A new window will open up as shown below:


    • General – Build definition name: Enter build definition name
  4. Select workspace


    • Status: Active
    • Source Control Folder: TFS server path project
  5. Select “Project file”, click create button:


  6. MSBuild Project file creation wizard will open up. In this, select the item as shown below:


  7. Click next and leave other options as is & click FINISH button.
  8. Leave retention policy section as it is.


  9. Now select Build Defaults
    1. Build Agent: Should select build agent name that we have created in Step 2 – Create TFS Build Agent
    2. Builds will be staged: should provide shared path which TFS server has access
  10. Trigger section allows to configure TFS build to run at those intervals
  11. 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


  3. Select as shown below:
    1. Build Definition name
    2. Build Agent name
    3. Drop folder
    4. Priority


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


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

Happy coding… hope this helps!


  • 29th October, 2011: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
romull24-Jun-12 1:53
memberromull24-Jun-12 1:53 
It seems the all was taken out of context. The article was written very roughly. What about TFS version? But the theme chosen is very actual.
QuestionWhere do you add the custom task? Pin
L Hills1-Nov-11 6:55
memberL Hills1-Nov-11 6:55 
AnswerRe: Where do you add the custom task? Pin
Bangla Gopal Surya1-Nov-11 18:40
memberBangla Gopal Surya1-Nov-11 18:40 
GeneralMy vote of 2 Pin
Mohammad_Denmark1-Nov-11 6:25
memberMohammad_Denmark1-Nov-11 6:25 
GeneralMy vote of 5 Pin
jawed.ace30-Oct-11 23:49
memberjawed.ace30-Oct-11 23:49 
GeneralRe: My vote of 5 Pin
Bangla Gopal Surya1-Nov-11 2:51
memberBangla Gopal Surya1-Nov-11 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.180621.3 | Last Updated 30 Oct 2011
Article Copyright 2011 by Bangla Gopal Surya Prakash
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid