我一直在尝试访问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 :(
我有两个问题:
答案 0 :(得分:1)
关于问题#1,您可以在Introducing the TfsConnection, TfsConfigurationServer and TfsTeamProjectCollection Classes中找到一些问题。简而言之,您可以拥有许多用户数据库,即Collection,由单个TFS实例(即服务器)管理。
答案 1 :(得分:0)
我刚刚发现了问题所在。我只需要替换最后一行:
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);
}