Friday, September 11, 2009

Retrieving Associated Work Items for Build In TFS

I’m working on a deployment system for several of the products we publish at Auckland Software. As part of this we need to ‘publish’ the results of a successful TFS build to the QA environment for testing, and we’re trying to automate that process as much as possible. To that end, I’ve been writing some code to integrate to TFS, and one of things I needed to do was obtain the list of work items associated with the build.

I found several articles that showed this was possible with the GetAssociatedWorkItems method of the InformationNodeConverters object. The problem was, I couldn’t find where the InformationNodeConverters class lived. Some more searching on the internet revealed it was in the Microsoft.TeamFoundation.Build.Client namespace, in the Microsoft.TeamFoundation.Build.Client.dll file.

The next problem was that I couldn’t find the Microsoft.TeamFoundation.Build.Client.dll file, searching my PC for it I found it in several locations (some applications had installed their own copies) but the best looking location to reference it from seemed to be

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies

Once I had my reference I could call the method I needed, but it didn’t work ! I had a valid build object to pass to the method, and the method succeeded without errors, but no work items were returned. I spent some time searching the internet for this problem, but didn’t find any reference to it. Eventually I started playing around with the code on my own, and I found the method only returned work items if I first called the RefreshAllDetails method of the build object first. This method took a second or so to execute, but without it the GetAssociatedWorkItems method didn’t work anyway.

It may be possible to call the Refresh method of the build object instead (and that might be faster), but I haven’t yet figured out the correct parameters to pass it. Calling the RefreshMinimalDetails method doesn’t help, just in case you’re wondering.

So if you’re trying to get work items related to a build and you’re not getting any results, try calling the RefreshAllDetails method of the build object first.


Technorati Tags: ,,,

No comments:

Post a Comment