查找与工作项关联的更改集或具有特定注释TFS Api

我正在尝试使用Microsoft.TeamFoundation.WorkItemTracking.Client查找与工作项关联的所有更改集。 使用查询我能够获得有关工作项的信息,但是我无法找到有关我正在返回的对象的任何变更集信息。 除此之外,还有一些变更集与特定工作项无关,但可通过注释轻松识别。 有没有快速的方法来使用tfs api找到这些?

编辑:这不是如何使用tfs api获取与变更集ID相关联的工作项的副本? b / c在该问题中,人员有变更集,并希望找到相关的工作项目。 在我的情况下,我有一个工作项,我想找到与特定工作项相关的所有变更集。 除此之外,我需要找到评论中具有特定字符串的所有变更集。

经过更多关于这个主题的Google搜索和探索tfs API之后我最终得到了:

如果您所有的更改集都链接到工作项(不是我的情况,但这是我最初询问的):

// based on https://etoptanci.wordpress.com/2011/05/04/seeing-all-code-changes-for-a-work-item/ private static void GetChangesForWorkItem() { var configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(@"http://myserver:8080/tfs")); var tpcService = configurationServer.GetService(); var collectionNodes = configurationServer.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); var collectionNode = collectionNodes.First(x => x.Resource.DisplayName == ""); // Use the InstanceId property to get the team project collection Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); TfsTeamProjectCollection collection = configurationServer.GetTeamProjectCollection(collectionId); var vcs = collection.GetService(); var store = new WorkItemStore(collection); var workItems = new List() { store.GetWorkItem(1123), store.GetWorkItem(1145), }; var associatedChangesets = new List(); foreach (var workItem in workItems) { foreach (var link in workItem.Links) { if((link==null) || !(link is ExternalLink)) continue; string externalLink = ((ExternalLink)link).LinkedArtifactUri; var artifact =LinkingUtilities.DecodeUri(externalLink); if (artifact.ArtifactType == "Changeset") associatedChangesets.Add(vcs.ArtifactProvider.GetChangeset(new Uri(externalLink))); } } Console.WriteLine(associatedChangesets.Select(x=>x.ChangesetId).OrderBy(x => x)); } 

如果您还需要通过注释获得,那么您将为日期范围选择所有更改集,然后通过Changeset.Comment过滤掉这是一个字符串。

检查REST API :

 GET https://{instance}/defaultcollection/_apis/tfvc/changesets/{id}?api-version={version}[&includedetails={boolean}&includeworkitems={boolean}&includesourcerenames={boolean}&maxchangecount={int}&maxcommentlength={int}] 

您也可以使用RestAPI(如第一个答案中所述)

https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#with-links-and-attachments

你需要用rel ==“ArtifactLink”过滤掉“relations”数组