如何查找与工作项关联的变更集

时间:2015-05-14 16:42:03

标签: c# tfs

我正在努力让所有变更集都与工作项目相关联我能够获得工作项目,但无法将变更集与工作项目联系起来。

下面的

是我用来获取工作项目的代码块

    TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
            tfsUri);
    WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));

    WorkItemCollection queryResults = workItemStore.Query(
        string.Format("Select [Title] " +
        "From WorkItems " +
        "Where [ID] = '{0}' ", itemId));

    foreach (WorkItem workItem in queryResults)
    {
        Console.WriteLine(workItem.Title);
    }

还尝试了以下解决方案,但它无法正常工作

http://blogs.msdn.com/b/jmanning/archive/2005/09/21/472524.aspx

using System;
using System.Collections.Generic;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation;

class ChangesetsFromWorkItems
{
    static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            Console.Error.Write("Usage: ChangesetsFromWorkItems <server> <workitemid> [workitemid...]");
            Environment.Exit(1);
        }

        TeamFoundationServer server = TeamFoundationServerFactory.GetServer(args[0]);
        WorkItemStore wiStore = (WorkItemStore)server.GetService(typeof(WorkItemStore));

        int workItemId;
        for (int i = 1; i < args.Length; i++)
        {
            if (!int.TryParse(args[i], out workItemId))
            {
                Console.Error.WriteLine("ignoring unparseable argument {0}", args[i]);
                continue;
            }
            WorkItem workItem = wiStore.GetWorkItem(workItemId);
            List<string> associatedChangesets = new List<string>();
            foreach (Link link in workItem.Links)
            {
                ExternalLink extLink = link as ExternalLink;
                if (extLink != null)
                {
                    ArtifactId artifact = LinkingUtilities.DecodeUri(extLink.LinkedArtifactUri);
                    if (String.Equals(artifact.ArtifactType, "Changeset", StringComparison.Ordinal))
                    {
                        associatedChangesets.Add(artifact.ToolSpecificId);
                    }
                }
            }
            string changesets = String.Join(", ", associatedChangesets.ToArray());
            Console.WriteLine("WorkItem {0} has associated changeset(s): {1}", workItemId, changesets);
        }
    }
}

低于条件总是返回false,因为extLink为空

if (extLink != null)

1 个答案:

答案 0 :(得分:4)

如果没有ExternalLink(例如,没有链接可以转换为此类型),则没有与工作项关联的外部链接。

尝试查看调试器中的WorkItem.Links集合,以查看附加了哪种链接。