How can I query work items and their linked changesets in TFS?

丶灬走出姿态 提交于 2019-11-28 09:55:45

An option is to use the TFS API like the following snippet.

var projectCollection = new TfsTeamProjectCollection(
    new Uri("http://localhost:8080/tfs"),
    new UICredentialsProvider());
projectCollection.EnsureAuthenticated();
var workItemStore = projectCollection.GetService<WorkItemStore>();
var versionControlServer = projectCollection.GetService<VersionControlServer>();
var artifactProvider = versionControlServer.ArtifactProvider;
var project = workItemStore.Projects["Test01.MSFAgile.v5"];
var teamQueryFolder = project.QueryHierarchy["Team Queries"] as QueryFolder;
var query = teamQueryFolder["My Tasks"];
var queryDefinition = workItemStore.GetQueryDefinition(query.Id);
var variables = new Dictionary<string, string>
{
    {"project", query.Project.Name}
};
var workItemCollection = workItemStore.Query(
    queryDefinition.QueryText,
    variables);
foreach (WorkItem workItem in workItemCollection)
{
    Console.WriteLine("WI: {0}, Title: {1}", workItem.Id, workItem.Title);
    foreach (var changeset in
        workItem.Links
            .OfType<ExternalLink>()
            .Select(link => artifactProvider
                .GetChangeset(new Uri(link.LinkedArtifactUri))))
    {
        Console.WriteLine(
            "CS: {0}, Comment: {1}",
            changeset.ChangesetId,
            changeset.Comment);
    }
}

I just attended the Webinar Improving Developer and Tester Collaboration where I posed my question. Instructor Ken Arneson of alpi.com confirmed that links to changesets are not reportable through Query Editor in TFS Team Explorer. To access links to changesets, other tools must be used to access the "Cube". I have more to learn.

If you do a Query and include external link count >0 this will actually give you all work items that have changesets associated with it.

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