2016-08-12 65 views
-1

我正在開發一個c#控制檯應用程序,在該應用程序中我想連接到我的TFS服務器並從中訪問信息。使用c#控制檯應用程序連接到TFS服務器

我的TFS服務器是:http://vstfpg05:8080/tfs/ESITAPP

基本上,我們維持通過TFS票務系統,我想訪問門票的服務名稱。

enter image description here

以上是我的TFS系統剪斷。

+0

你好,歡迎來到StackOverflow。請花一些時間閱讀幫助頁面,尤其是名爲[「我可以詢問什麼主題?」(http://stackoverflow.com/help/on-topic)和[「我應該問什麼類型的問題避免問?「](http://stackoverflow.com/help/dont-ask)。更重要的是,請閱讀[Stack Overflow問題清單](http://meta.stackexchange.com/q/156810/204922)。您可能還想了解[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 – lokusking

+0

出租車請告訴我如何連接到我的tfs實例並從中訪問工作項? – dotnetman

+0

您提供的屏幕截圖中的內容是查詢,而不是工作項。你想通過C $控制檯應用程序獲得什麼?查詢或工作項目? –

回答

2

可以以編程方式連接到運行團隊基礎,然後訪問該服務器上的團隊項目如果使用客戶端API用下面的例子服務器:

using System; 
using System.Collections.ObjectModel; 
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.Framework.Common; 
using Microsoft.TeamFoundation.Framework.Client; 

namespace TfsApplication 
{ 
    class Program 
    { 
     static void Main(String[] args) 
     { 
      // Connect to Team Foundation Server 
      //  Server is the name of the server that is running the application tier for Team Foundation. 
      //  Port is the port that Team Foundation uses. The default port is 8080. 
      //  VDir is the virtual path to the Team Foundation application. The default path is tfs. 
      Uri tfsUri = (args.Length < 1) ? 
       new Uri("http://Server:Port/VDir") : new Uri(args[0]); 

      TfsConfigurationServer configurationServer = 
       TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); 

      // Get the catalog of team project collections 
      ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
       new[] { CatalogResourceTypes.ProjectCollection }, 
       false, CatalogQueryOptions.None); 

      // List the team project collections 
      foreach (CatalogNode collectionNode in collectionNodes) 
      { 
       // Use the InstanceId property to get the team project collection 
       Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); 
       TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); 

       // Print the name of the team project collection 
       Console.WriteLine("Collection: " + teamProjectCollection.Name); 

       // Get a catalog of team projects for the collection 
       ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
        new[] { CatalogResourceTypes.TeamProject }, 
        false, CatalogQueryOptions.None); 

       // List the team projects in the collection 
       foreach (CatalogNode projectNode in projectNodes) 
       { 
        Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName); 
       } 
      } 
     } 
    } 
} 

更多詳細信息,請參閱本來自MSDN的教程:Connect to Team Foundation Server from a Console Application

+1

謝謝!它運作良好 – dotnetman

相關問題