Just like everything that requires coding with (or against?) TFS API – this was not a small task. This took a while for me to understand and figure out, especially since how you work with the API keeps changing depending on the version of TFS. Therefore be fully aware these instructions are for TFS 2010 and can definitely be retrofitted to work with other versions.

Getting your Work Item
So you have a work item ID and all you want to know are which files you have associated with this work item – should be simple huh? Not so much. First you need to get your individual work item, but why would that be so hard? Well it wasn’t straight forward either – you need to write a query to get your work item because the API for some reason or another doesn’t have a stock way of doing this which is just odd. My goal was to get a work item for a particular team project with a specific work item ID.

Work Item Hierarchy
There is a hierarchy with a work item and it goes something like this:
There is your Work Item and your work item contains Links. Links can be changes, but don’t necessarily have to be – plus a Link is a Link – it isn’t explicitly anything but that. So don’t bother looking for a “Changes” collection because it doesn’t exist. You have to convert your Links to Changes by trial – which again, shocked that there is no stock method for this.

The Code
I am providing an entire class I wrote that will return a list of files changed for a work item. I took the change object and converted it to my own type called “FileItem” so I can do further manipulations in the future. You must pass in your TFS URI first thing. There are some private properties at the top of the class that are used all over the class. You literally need a combination of these objects for just about everything.

There are some additional utilities in the class below – think of them as a bonus.

DLLs Referenced in the Code
You need to reference 5 dlls to make this code work. Those dlls are:

  • Microsoft.TeamFoundation.Client
  • Microsoft.TeamFoundation.Common
  • Microsoft.TeamFoundation.VersionControl.Client
  • Microsoft.TeamFoundation.VersionControl.Common
  • Microsoft.TeamFoundation.WorkItemTracking.Client

You can locate the dlls by:

  1. Going to your project, right click on the References folder
  2. Select “Add Reference…” from the context menu
  3. Click on the “Assemblies” option in the left pane
  4. Click on “Extensions” under the “Assemblies” option tree
  5. Select the aforementioned libraries (above list) and make sure to select version “”
TFS DLL Gotcha 1
  • I can’t find the dlls you mentioned above
  • I don’t have the version of the dlls you mentioned above
  • I tried deploying this code to my web server and it won’t run, it says I am missing components
I have the same answer for the above bullet points. You must have the Team Foundation Server Client installed on your system. If you are installing this on a server, the client must be installed on the server.
TFS DLL Gotcha 2
Unfortunately these dlls are x86 – so you must set your project to “Any CPU” and if you are hosting in IIS you must run your application pool in 32 bit mode (enabled 32 bit applications – set to true).

Links that helped me figure this mess out

Leave a Reply

Your email address will not be published. Required fields are marked *