【问题标题】:Programatically access TFS account to get project names and work items以编程方式访问 TFS 帐户以获取项目名称和工作项
【发布时间】:2016-10-11 14:25:34
【问题描述】:

我一直在尝试访问 TFS 帐户(以编程方式使用 TFS SDK)以获取项目名称、工作项名称和每个工作项的开发时间等信息。

我无法获取项目或工作项信息,但我能够使用 TfsTeamProjectCollection 类进行身份验证和访问 TFS。

但是,使用 TfsConfigurationServer 类,我永远无法对服务器进行身份验证。很遗憾,因为我在网上看到的大多数示例都使用了这个 TfsConfigurationServer 类。

允许我访问 TFS 的代码:

// Connect to Team Foundation Server.
NetworkCredential netCred = new NetworkCredential("myEmail@email.com", "myPassword");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tfs.gfi.pt:4430/tfs/gfi/"),tfsCred);

tpc.Authenticate(); // This one works, and when I enter tpc I can see I am correctly signed-in in TFS (I can for instance check my full name)

ITeamProjectCollectionService projCollect = tpc.GetService<ITeamProjectCollectionService>(); //returns null :(

我有两个问题:

  1. TfsConfigurationServer 和 TfsTeamProjectCollection 有什么区别?我知道第一个引导我进入服务器级,第二个引导我进入集合级,但是,服务器级和集合级是什么?
  2. 当我完全能够登录时,为什么我无法获取 projectCollection(当我确定我在 TFS 上有 2 个项目时,为什么最后一行返回 null)?

【问题讨论】:

标签: c# tfs tfs-sdk


【解决方案1】:

关于问题#1,您可以在Introducing the TfsConnection, TfsConfigurationServer and TfsTeamProjectCollection Classes 中找到一些原因。很快,您可以拥有多个用户数据库,即集合,由单个 TFS 实例(即服务器)管理。

【讨论】:

    【解决方案2】:

    我刚刚发现了问题所在。我只需要替换最后一行:

    ITeamProjectCollectionService projCollect = tpc.GetService<ITeamProjectCollectionService>(); //returns null :(
    

    作者:

    // Get the catalog of team project collections
    ReadOnlyCollection<CatalogNode> collectionNodes = tpc.CatalogNode.QueryChildren(
    new [] { CatalogResourceTypes.TeamProject},
    false, CatalogQueryOptions.None);
    
    // List the team project collections
    foreach (CatalogNode collectionNode in collectionNodes)
    {
        Console.WriteLine(collectionNode.Resource.DisplayName);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-29
      • 2011-02-20
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 2011-01-03
      相关资源
      最近更新 更多