Вы можете попробовать следующий код, чтобы получить список всех пользователей:
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);
}
}
}
}