TFS API控制台应用程序打开和关闭

时间:2015-11-30 23:58:34

标签: c# asp.net api tfs visual-studio-2015

我试图运行它,但控制台应用程序运行并关闭。

我猜测查询是空白还是空,但我确保有一个活动的工作项。

我只是想让它在这一点上撤回任何东西。

try
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://(server):8080/tfs/DefaultCollection"));

            var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));

            // Sample query string.
            string wiqlQuery = "SELECT System.ID, System.Title from workitems ";

            // Execute the query.
            WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);

            // Show the ID and Title of each WorkItem returned from the query.
            foreach (WorkItem workItem in witCollection)
            {
                Console.WriteLine("ID: {0}", workItem.Id);
                Console.WriteLine("Title: {0}", workItem.Title);
                Console.Read();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.Read();

        }

1 个答案:

答案 0 :(得分:1)

它必须已拉出 witCollection,导致foreach被跳过(因此控制台应用程序立即关闭)。如果它为null,则会得到NullReferenceException

请在此处阅读,看看是否有帮助:https://msdn.microsoft.com/en-us/library/bb130306.aspx