Warm tip: This article is reproduced from serverfault.com, please click

How to get Unique Display name for VSTS/TFS identity?

发布于 2018-04-20 19:32:54

I am a writing a .Net application using the VSTS/TFS Rest .Net libraries and in one place I need to update workitems' System.AssignedTo field values and while I do want to adhere to the new(ish), unique displayname rules for identity work item fields, I have a hard time finding a method to get the Unique display name(s) for given identities.

The old / client object model does have an explicit helper method to get these unique names, but I have not found any rest endpoint nor client api method that would provide the same.

So I am wondering, given a list of identities, how do I get their corresponding unique display names which I can use to unambiguously set identity work item fields?

Questioner
Jörg Battermann
Viewed
0
Eddie Chen - MSFT 2018-05-02 14:43:22
            String collectionUri = "http://collectionurl/";
            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("ProjectName","TeamName").Result;
            foreach (IdentityRef ir in irs)
            {
                Console.WriteLine(ir.UniqueName);
                Console.WriteLine(ir.DisplayName);
            }