Home > Team Foundation Server > TFS 2010 Beta 2 – Custom Work Item Controls. Step 1, Getting Started

TFS 2010 Beta 2 – Custom Work Item Controls. Step 1, Getting Started


Overview

A few months ago I spent a week or so getting my head around the Custom Work Item Controls in Team Foundation Server 2008. At the time it was obvious that a lot of value could be added to our development teams if we could add some additional custom work item functionality to our processes.

My original intent at the time was to build a work item explorer that could navigate through work items based on their relationships … but that is fairly redundant now that we have proper work item hierarchies in TFS 2010. This time my intention is to have a look at how we can improve the way we record our time against tasks within Team Foundation Server.

This post (Step 1, Getting Started) will cover the process of setting up the required project and setup files, creating a basic ‘Hello World’ custom work item control and loading that control into the work item interface.

Prerequisites:

  • Visual Studio 2008 or 2010 (for development)
  • Visual Studio 2010 Team Explorer Beta 2 (for testing)
  • Team Foundation Server 2010 Beta 2

Visual Studio Project Setup

Creating Custom Work Items Controls is much like creating any other control library in Visual Studio. The control itself is based on the standard UserControl base class, and should be setup within a .NET Class Library Project.

Before going any further, we’re going to need to add a reference to the TFS Work Item Tracking Controls assembly. This is installed as part of Visual Studio 2010, and can be found in the following folder:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.WorkItemTracking.Controls.dll

At a minimum, we’ll also need the following artefacts in our solution:

  • One User Control (WorkItemTimeSheetControl)
  • One Work Item Custom Control definition file (.wicc). Note that it is important to set the Build Action for this file to ‘Content’ on from the properties window.

Create the User Control

There is nothing overly special about a user control housed within a Work Item form – except that it implements the IWorkItemControl interface. For the moment the goal is only to create a user control and embed it within the Work Item form, so the control itself contains nothing more than the compulsory ‘Hello World’ label in bold 24pt black font.

We’ll setup the various members of the IWorkItemControl interface in more detail in a future post – for the moment a basic implementation with the default NotImplementedExceptions removed will do the job. Just create basic backing variables for any of the properties that need to be defined.

Create the Work Item Custom Control definition (WICC)

The .wicc file is an XML file that defines the custom control to be loaded within a work item. When a Custom Control is referenced within a Work Item Template, Visual Studio will look within the custom controls folder for a .wicc definition file that matches the name of the required custom control. In the case of current custom control, Visual Studio will be looking for a file named WorkItemTimeSheetControl.wicc.

The following XML is the contents of the WorkItemTimeSheetControl.wicc file:

<?xml
version=1.0
encoding=utf-8 ?>

<CustomControl
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd=http://www.w3.org/2001/XMLSchema>

<Assembly>TimeSheetControl.dll</Assembly>

<FullClassName>TimeSheetControl.WorkItemTimeSheetControl</FullClassName>

</CustomControl>

Create the Windows Installer

Unfortunately the runtime for a Work Item Custom Control is not defined on the Team Foundation Server instance, but rather must be installed on every Visual Studio client machine that will be interacting with the work item.

The one gotcha for the setup folder is that all the output must be installed on within the custom controls folder on the client machine. On Vista, this is located at C:\ProgramData\Microsoft\Team Foundation\Work Item Tracking\Custom Controls\10.0 … though this will vary depending on the OS.

  1. Create a new Setup Project within the solution
  2. Add a new ‘Custom Folder’ named CommonAppDataFolder to the output of the setup project.
  3. In the properties window for the new custom folder, set the Default Location to [CommonAppDataFolder].
  4. Create the folder structure shown in the screenshot above under the CommonAppDataFolder. (Microsoft, Team Foundation, Work Item Tracking, Custom Controls, 10.0)
  5. Add the Primary Output and Content Files from the user control class library we created earlier.
  6. Build and install the setup file on the local machine.

The client components are now all in place – the only remaining step is to add our custom control to one of the work item templates.

Modify the Work Item Template

I’m going to select the Task work item from the MSF for Agile Software Development 5.0 Beta 2 process templates as the testing work item template to apply our new custom control to.    

Using the following command the existing work item template for the Task work item can be extracted from the Team Foundation Server.

C:\>”C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\witadmin” exportwitd /collection:localhost\defaultcollection /p:”{ExistingProject}” /n:Task /f:Task.xml

A couple of notes here:

  1. The WITAdmin tool is new to TFS 2010. When working with TFS 2008 the witimport / witexport tools would be used instead.
  2. In TFS 2008 adding custom controls to a work item template broke the process editor power tool – so all operations to import / export the work items must be done by command line. I am not sure whether this is going to be supported in the TFS 2010 power toys or not.

Now that we’ve got the work item template extracted we need to modify it to include our custom work item control. I’ve chosen to add the control to a new tab at on the bottom half of the screen.

The XML fragment below shows the addition of the time sheet control to the Task work item file in bold black font. Make sure that the ‘Type’ attribute for the Control node is set to the name of the .wicc file that has been deployed to the client machines.

        …

    <Tab
Label=Attachments>

    <Control
Type=AttachmentsControl
LabelPosition=Top />

        </Tab>

            <Tab Label=”TimeSheets”>

                <Control Type=”WorkItemTimeSheetControl” LabelPosition=”Top” />

            </Tab>

        </TabGroup>

</Layout>

</FORM>

</WORKITEMTYPE>

</witd:WITD>

The modified work item can then be imported back into TFS 2010 using the following command:

C:\TFS>”C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\witadmin” importwitd /collection:localhost\defaultcollection /p:”{ExistingProjectName}” /f:Task.xml

Testing the Changes …

Back on the Visual Studio client machine, load up an instance of Visual Studio 2010 Team Explorer Beta 2 and open a Task from within the team project that has had the modified work item template loaded. Assuming everything has gone to plan a new tab should exist on the Work Item form, and the custom control should have loaded and displayed correctly.

One gotcha to keep in mind here – Team Explorer will cache the work item templates and controls – so it may be necessary to restart the Team Explorer client in order to see the updated layout.

Next Steps

Hopefully this ‘getting started’ post is of some use to others as they work through this process … or at least will help me out next time I get some time free to continue with this side project J

Now that we’ve got a user control successfully loading from within the work item layout, my next (likely) steps include:

  • Adding interaction with the Work Item data model
  • Investigating how / if the TFS Web Interface can have a similar custom control applied
  • Investigating whether using WPF controls will simplify the implementation of think client / web client work item templates
  • Putting together some actual logic to solve the initial issue of time sheeting!
About these ads
  1. Rafael L.
    May 21, 2010 at 10:00 pm | #1

    I want to do this too. We already have a database with workitems and task record time. I would like to integrate the workitems and to note time over taks on VS.

    Nice post.

  2. Charlene J
    October 8, 2010 at 1:53 pm | #2

    Hi, in the section about creating a setup project, when you mention adding the “Primary Output and Content Files” what files are you referring to? I assume the content file is the .wicc file, but what is the primary output file? The dll?

    Thanks!

    • October 17, 2010 at 10:42 am | #3

      Hello,

      The output files required are all the compiled dll’s and content files from the TimeSheetControl project.

      I’ve added these by right clicking on the folder for the Setup Project, and selecting “Add –> Project Output”. In the next dialog I’ve selected Primary Output and Content Files. I’ve also included the debug symbols for the moment, just to make any issue diagnosis a little easier.

      Regards,
      Nick

  3. Dylan
    January 18, 2012 at 8:17 pm | #4

    Hey nick i need your help badly.

    At my company i have been busy installing the TFS Timesheet you made.
    I ran the setup frst.
    In visual studio everything works.
    No problem there.

    Only on web acces it says the TimesheetControl can not be loaded.

    I have tried putting your objectmodel.dll in the GAC.. did not work..

    What am i supposed to do?
    I have searched everywhere and i can not find an d answer.
    Please help!

    the error i am receiving in web acces:

    Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls.WorkItemFormException: Unable to load custom control manifest for ‘WorkItemTimeSheetControl’.
    at Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls.ControlFactory.GetCustomControlType(String controlName)
    at Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls.ControlFactory.GetControlType(ControlDefinition controlDefinition)
    at Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls.ControlFactory.CreateCustomControl(ControlDefinition controlDefinition)
    at Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls.ControlElement.CreateWorkItemControl()
    at Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls.ControlElement.BuildWebControl()

    Kind Regards

    • January 19, 2012 at 8:40 pm | #5

      Hi Dylan,
      I have to admit, the main Time sheet control was originally designed to work with Visual Studio as the host, rather than TWSA.

      Having said that, a lot of people were asking about a TSWA component, so I did start working on a release some time back. Unfortunately I have not been able to get this beyond a beta stage, party due to time constraints, and party because we haven’t been using TSWA ourselves all that heavily.

      The beta is available at the following download link:
      http://tfstimesheets.codeplex.com/releases/view/64141

      Current release notes (as I say, this is very beta …):

      * A first draft (very unpolished at this stage) of a Team System Web Access Custom Control for the TFS Timesheet.
      * Adding a timesheet entry row causes the work item to save, and ignores any other changes made on the screen
      * No validators implemented yet
      * Username is detected as the account name, not display name for a user
      * No ability to delete time sheet entries (can still be deleted in the windows client)

      Hopefully this helps, though I think that you will find this a little raw in it’s current form. Sorry this is not in a more complete state for you.

      Regards,

      Nick

      • Dylan
        January 19, 2012 at 10:39 pm | #6

        Hi Nick,
        Thanks for the quick response.
        I will try out your beta version.

        I wont promise everything, but if i polish it i will post you the code.
        Redards
        Dylan

      • Dylan
        January 26, 2012 at 10:11 pm | #7

        Hey nick,
        Even with that release i didnt got it working,
        i get no component at all , just the same error message.
        Are there thinkgs i need to specify in the WorkItem Definition?

        Did it work for you? and so which steps did you take?

        Kind Regards
        Dylan

  1. November 14, 2009 at 6:21 pm | #1
  2. May 30, 2010 at 11:13 pm | #2
  3. May 8, 2012 at 12:43 am | #3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: