As most users of TFS have become aware of, it is not possible to directly create a screenshot in a TFS Work Item. This is particularly awkward when working with bugs in TFS, since commonly a key part of a bug report is to include a screen-dump of the issue at hand. There are a few attempts to solve this problem (Automatically raise bugs from IE, Snag-it output for TFS) but none I’ve seen addresses the problem that you actually want to do the capture from the work item itself.
So having thought about this for a while I decided to write a TFS Work Item Custom Control that can create new attachments to a work item based on an image available on the Windows Clipboard. So the scenario for the user of the control is to find the window to attach to a work item and then press “print screen” for the entire desktop or “alt-gr print screen” to capture a specific window. The content of the clipboard will then be saved as an attachment. Simple enough was my idea.
The code for the Work Item Screenshot Control can be downloaded here: TFSScreenshotControl.zip (26,39 KB)
There is very little documentation available on how to develop custom controls for TFS work item tracking. The references I’ve found must useful are these:
When it comes to debugging WIT custom controls, I can only say that it works pretty well be attaching one Visual Studio instance with the control project loaded to another running the Team Explorer and the work item to test. The most annoying thing is that the VS instance having opened a work item form with the custom control on it will lock the control file so in order to test an updated version Visual Studio must be restarted.
The Capture control can be added to any work item tracking type definition. Typically you would provide a label and then the Capture button, similar to the following image:
And here’s a cool feature – if the clipboard doesn’t contain an image then the Capture button is disabled. It will become enable as soon as the user presses “print screen” or “alt-gr print-screen”.
When the button is pressed a “Save As Attachment” dialog is shown. The dialog lets the user enter the attachment name and comment as usual. Pressing OK will create a new attachment to the work item.
It is also possible to click on the preview image to bring up a larger window with the screen shot:
To make the capture control even more useful, I’ve also implemented an alternative “File Attachment” control. This control works just like the standard control but also provides the Capture feature.
To use the control first create a work item type that contains the image. In essence the only thing that needs to be done is to include a new control in the <FORM> section in the work item XML. The following examples shows the syntax for the ScreenShot control and the FileAttachment control respectively:
<Control Type="ScreenshotControl" Label="Screenshot:" LabelPosition="Left" />
<Tab Label="File Attachments">
<Control Type="AttachmentsControl2" LabelPosition="Top" />
After that the control and its associated .wicc files need to be deployed locally on each machine using the control (and no, the TFS web client will currently not handle custom controls). Team Explorer searches for custom controls in folder “Microsoft\Team Foundation\Work Item Tracking\Custom Controls” under Environment.SpecialFolder.CommonApplicationData folder first, then under Environment.SpecialFolder.LocalApplicationData.
So, that was it. Hopefully these little controls will fill part of the gap when it comes to handling screenshots in TFS work items.