开发者

TFS2010: How to link a WorkItem to a ChangeSet

开发者 https://www.devze.com 2023-04-03 18:38 出处:网络
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:

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 changese开发者_运维百科t. Does anyone have an idea how to achieve this?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消