3
votes

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 OKto 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.

2

2 Answers

3
votes

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:

1
votes

The linking part can be done as @Enrico suggests.
Your other only challenge is to discover and select the appropriate changesets in order to fill Enricos' changeSetsIds.

I 'm not aware of way to implement this using TFS-SDK, yet there are options to do this:
You either pipe the output of a tfpt searchcs, or make use of this VS extension. The VS extension operates even with regex, but it's copy/paste is somehow not optimum.