I have a User Story in TFS 2010 and I want to link to it all the changesets that are relevant for the User Story.
So in the User Story, I go to the All Links
tab, click on Link to
, change the link type from Child
to Changeset
, click on Browse
, fill in my name under By user:
and click on Find
. I am now presented with a list of all my changesets.
My problem is that I have several dozen changesets that I want to attach to the User Story, but that I can't do a multiple select. I have to select a changeset, and click twice on OK
to link to it. And then I have to repeat the whole process for the next one. And so on...
This gets boring rather quickly. What I ideally want to do is in the Find Changesets
window to do a search on keywords in the commit comments, select all the changesets that are relevant and link to all of them at once.
Is there a way to achieve this in TFS 2010, or is there another way to achieve the same result.
Yes, you can do this programmatically using the Team Foundation Server API.
Here's an example:
var server = new TeamFoundationServer(serverName);
var workItemStore = (WorkItemStore)server.GetService(typeof(WorkItemStore));
var project = workItemStore.Projects[projectName];
var userStoryId = 9;
var changeSetsIds = new[] { 2, 3, 4, 5 };
var userStory = project.Store.GetWorkItem(userStoryId);
foreach (var changeSetId in changeSetsIds)
{
var changeSetLink = new RelatedLink(changeSetId);
userStory.Links.Add(changeSetLink);
}
userStory.Save();
See also: