Getting Naren's Work Item Custom Control To Work
Naren has given us a great blog post to get us started on
How to use Custom Control in a Work Item Type. My blog post today is about what I did to get Naren's example working.
From Naren's blog post, I downloaded the WitCustomControlSample.zip file. This file contains his control example, as well as the .wicc file for specifying the custom control, and a modified version of the Bug work item type called Bug-CustomControl.xml. I unzipped this file to c:\WitCustomControlSample on my VPC.
Next, I installed the Team Foundation Server SP1 Beta patch: VS80sp1-KB922996-X86-Beta-ENU.exe. You can get the patch from http://connect.microsoft.com.
Using Visual Studio, I opened the C:\WitCustomControlSample\WitCustomControlSample.sln solution file, to open the project and solution. When I build the solution, I received the following three errors:
-
The type or namespace name 'Controls' does not exist in the namespace 'Microsoft.TeamFoundation.WorkItemTracking' (are you missing an assembly reference?)
-
The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
-
The type or namespace name 'IWorkItemControl' could not be found (are you missing a using directive or an assembly reference?)
In Visual Studio, in Solution Explorer, under the WitCustomControlSample project, you can drill down into the references folder. In there, two of the references have a yellow icon beside them, indicating there is a problem:
- Microsoft.TeamFoundation.WorkItemTracking.Controls
- Microsoft.VisualStudio.TeamFoundation.WorkItemTracking
We need to fix the reference to these two files. Right-click on the References folder and select "Add Reference". This opens the Add Reference window. Click on the Browse tab. Navigate to "c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies" and select the following DLLs to add references to them:
- Microsoft.TeamFoundation.WorkItemTracking.Controls.dll
- Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.dll
The yellow icons on these to references now disappears. If you build the solution again, it builds successfully. Now that we have the custom control building correctly, the next step is to install the custom control for use.
To install the custom control, you need to copy the control DLL to a certain spot on your machine, and define a .wicc file for the custom control. Naren talks about these in more detail in his post, so I won't go into those here at this time. Under C:\Documents and Settings\All Users\Application Data\Microsoft I created the following directory: Team Foundation\Work Item Tracking\Custom Controls. I copied the custom control DLL I created, WitCustomControlSample.dll, from C:\WitCustomControlSample\bin\Debug to the directory I just created: c:\Documents and Settings\All Users\Application Data\Microsoft\Team Foundation\Work Item Tracking\Custom Controls.
Next, I copied the .wicc file Naren provided, WorkItemIdReference.wicc, from C:\WitCustomControlSample to c:\Documents and Settings\All Users\Application Data\Microsoft\Team Foundation\Work Item Tracking\Custom Controls. At this point, the control is installed and ready to be used. Now we need to add the custom control to a work item type and test it.
Naren provides a Bug-CustomControl.xml file, which is a modified version of the Bug work item type, with the new custom control on it. All we need to do is use witimport.exe to upload this version of the Bug work item type to your Team Project. I created a new MSF Agile Team Project called MyTeamProject. I then opened a Visual Studio 2005 command prompt and go to C:\WitCustomControlSample. Using witimport.exe, load the Bug-CustomControl.xml work item type to the MyTeamProject team project:
witimport /f Bug-CustomControl.xml /t mytfs /p MyTeamProject
In Visual Studio, in Team Explorer, right-click on the MyTeamProject and select Refresh to ensure it is loaded with the latest updates. At this point, we are ready to try and create a new Bug-CustomControl work item and see if our custom control works. In Team Explorer, right-click on the Work Item folder and select "Add Work Item->Bug-CustomControl" to create a new Bug-CustomControl work item.
The above image shows the work item. Notice the "Duplicate ID" custom control is there.
Now let's interact with the custom control. Click the "…" to open the Find A Work Item window. Do a search using the All Work Items query, select a work item, and click OK.
As you can see, the work item id of the selected work item is now displayed in the custom control.
If you click on the work item id, it will open the work item in a new tab in Visual studio. Save the work item you are working on, and make a note of it's ID. Close the work item, and re-open it, to prove to yourself that the contents of the custom control were saved.
And there ya go, that is how I got Naren's example working. Up next, I'm going to create my own custom control, and series of custom controls.