TFS2010: How to link a WorkItem to a ChangeSet

丶灬走出姿态 提交于 2019-12-01 02:45:27

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/7333505/tfs2010-how-to-link-a-workitem-to-a-changeset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!