我正在尝试使用Microsoft.TeamFoundation.WorkItemTracking.Client查找与工作项关联的所有更改集.使用查询我能够获得有关工作项的信息,但是我无法找到有关我正在返回的对象的任何变更集信息.除此之外,还有一些变更集与特定工作项无关,但可通过评论轻松识别.有没有快速的方法来使用tfs api找到这些?
编辑:这不是如何使用tfs api获取与变更集ID相关联的工作项的副本?b/c在该问题中,人员有变更集,并希望找到相关的工作项目.在我的情况下,我有一个工作项,我想找到与特定工作项相关的所有变更集.除此之外,我需要找到评论中具有特定字符串的所有变更集.
经过更多关于这个主题的谷歌搜索和探索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<ITeamProjectCollectionService>();
var collectionNodes = configurationServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false, CatalogQueryOptions.None);
var collectionNode = collectionNodes.First(x => x.Resource.DisplayName == "<collection name>");
// 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<VersionControlServer>();
var store = new WorkItemStore(collection);
var workItems = new List<WorkItem>()
{
store.GetWorkItem(1123),
store.GetWorkItem(1145),
};
var associatedChangesets = new List<Changeset>();
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));
}
Run Code Online (Sandbox Code Playgroud)
如果您还需要通过注释获取,那么您将为日期范围选择所有更改集,然后通过Changeset.Comment过滤掉这是一个字符串.