Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS2010: How to link a WorkItem to a ChangeSet

Tags:

c#

I would like to programatically link WorkItems to Changesets.

At the moment I am already creating work items from my c# code and saving them to the TFS. The code looks as follows:

WorkItem item = new WorkItem(project.WorkItemTypes["CustomItem"]);            
item.Fields["CustomField1"].Value = someValue;
item.Fields["CustomField2"].Value = someValue;
item.Fields["CustomField3"].Value = someValue;
item.Validate();
item.Save();

This part of the code works fine. Now I would like to associate the newly created work item to an existing changeset. I am getting the changeset using:

VersionControlServer service = collection.GetService<VersionControlServer>();
Changeset changeset = service.GetChangeset(123123, true, true);

However, I can only iterate through the existing work items. I cannot add a new work item to this changeset. Does anyone have an idea how to achieve this?

like image 643
Christian Avatar asked Sep 07 '11 11:09

Christian


1 Answers

I found out how to do this by trail-and-error method:

WorkItemStore store = new WorkItemStore(collection);
Changeset changeset = service.GetChangeset(123, true, true);

WorkItem item = new WorkItem(project.WorkItemTypes["CustomItem"]);     
item.Links.Add(new ExternalLink(store.RegisteredLinkTypes[ArtifactLinkIds.Changeset], changeset.ArtifactUri.AbsoluteUri));       
item.Fields["CustomField1"].Value = someValue;
item.Fields["CustomField2"].Value = someValue;
item.Fields["CustomField3"].Value = someValue;
item.Validate();
item.Save();

I hope this will help someone else in the future! :)

Christian

like image 138
Christian Avatar answered Sep 29 '22 02:09

Christian