2

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();

This results in the following exception: API resource location 7a4d9ee9-3433-4347-b47a-7a80f1cf307e is not registered on (tfs link removed for privacy reasons)

2

1 Answer 1

3

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);
            }
        }
    }
}

Update:

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);
        }

        }
    }
}
3
  • The user part will be useful. I am however dealing with multiple teams that could be removed an new ones can be added. Therefore I would not want them to be hard coded. Do you think it is because that API doesn't exist inside of TFS 2017? but does in 2018?
    – Rocco
    May 4, 2018 at 10:25
  • I'm sorry I wrote I wanted a list of users! I actually wanted a list of teams!
    – Rocco
    May 4, 2018 at 14:28
  • Yeah that would work thanks for your help! I'll just have to manually get a list of the projects first! Just a shame that this company isn't using TFS 2018 yet. One call that gets all users > multiple calls!
    – Rocco
    May 7, 2018 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.