Cannot get a list of valid users in TFS for AssignedTo field while creating new Workitems via API

自闭症网瘾萝莉.ら 提交于 2019-12-10 16:09:28

问题


Hi I am trying to create new workitems via the TFS API and this is the method I have used below to get a list of valid users who can be assigned workitems. Somehow, it gives me a null reference exception on validUserSids line. Anyone know what's wrong here?

private string[] TFSUsers(string server)
    {
        // Get a Reference to Team Foundation Server.
        TeamFoundationServer tfs = tfsdata.GetTFS(server);
        // Get a reference to Group Security Service.
        IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
        // Resolve to SIDs
        Identity validUserSids = gss.ReadIdentity(SearchFactor.AccountName, "TFS Valid Users", QueryMembership.Expanded);
        // Resolve to actual users
        Identity[] validUsers = gss.ReadIdentities(SearchFactor.Sid, validUserSids.Members, QueryMembership.None);
        List<string> Users = new List<string>();
        foreach (Identity user in validUsers)
        {
            Users.Add(user.DisplayName);
        }
        return Users.ToArray();
    }

回答1:


Here's how you would get the list of users in TFS:

var tfs = TeamFoundationServerFactory.GetServer("http://vstspioneer:8080/tfs/VSTSDF");
var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
var allowedValues = workItemStore.FieldDefinitions[CoreField.AssignedTo].AllowedValues;

foreach (String value in allowedValues)
{
    Console.WriteLine(value);
}


来源:https://stackoverflow.com/questions/1565296/cannot-get-a-list-of-valid-users-in-tfs-for-assignedto-field-while-creating-new

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!