尝试通过客户端库获取 TFS 用户列表 [英] Trying to get list of TFS users trough client library
本文介绍了尝试通过客户端库获取 TFS 用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码获取我的 TFS 服务器(2017)上所有团队的列表,并且客户端库版本是最新预览版.
I'm trying to get a list of all teams on my TFS server(2017) with the following code and the client libraries version is the latest preview.
var teamclient = await Connection.GetClientAsync<TeamHttpClient>();
var teams = await teamclient.GetAllTeamsAsync();
这会导致以下异常:API 资源位置 7a4d9ee9-3433-4347-b47a-7a80f1cf307e 未注册(出于隐私原因删除了 tfs 链接)
推荐答案
您可以尝试以下代码列出所有用户:
You could try the following code to list all users:
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);
}
或者您可以使用以下代码获取每个团队中的用户:
Or you could use the following code to get users in each team:
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);
}
}
}
}
这篇关于尝试通过客户端库获取 TFS 用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文