我正在尝试使用以下代码获取 TFS 服务器(2017)上所有团队的列表,并且客户端库版本是最新预览版。
var teamclient = await Connection.GetClientAsync<TeamHttpClient>();
var teams = await teamclient.GetAllTeamsAsync();
这会导致以下异常: API 资源位置 7a4d9ee9-3433-4347-b47a-7a80f1cf307e 未注册(出于隐私原因删除了 tfs 链接)
最佳答案
您可以尝试以下代码来列出所有用户:
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("url"));
tfs.EnsureAuthenticated();
IGroupSecurityService gss = tfs.GetService<IGroupSecurityService>();
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);
foreach (Identity user in UserId)
{
Console.WriteLine(user.AccountName);
Console.WriteLine(user.DisplayName);
}
或者您可以使用以下代码来获取每个团队中的用户:
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
namespace GetUser
{
class Program
{
static void Main(string[] args)
{
String collectionUri = "http://TFS2017:8080/tfs/defaultcollection";
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
TeamHttpClient thc = connection.GetClient<TeamHttpClient>();
List<IdentityRef> irs = thc.GetTeamMembersAsync("TeamProject", "TeamProjectTeam").Result;
foreach (IdentityRef ir in irs)
{
Console.WriteLine(ir.DisplayName);
}
}
}
}
更新:
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
namespace GetUser
{
class Program
{
static void Main(string[] args)
{
String collectionUri = "http://TFS2017:8080/tfs/defaultcollection";
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
TeamHttpClient thc = connection.GetClient<TeamHttpClient>();
List<WebApiTeam> irs = thc.GetTeamsAsync("AgileProject").Result;
foreach (WebApiTeam ir in irs)
{
Console.WriteLine(ir.Name);
}
}
}
}
关于c# - 尝试通过客户端库获取 TFS 用户列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50152648/