如何以编程方式将用户添加到 TFS [英] How to add users programmatically to TFS
问题描述
我想以编程方式将用户添加到团队项目.我发现的解决方案是这样的:
I want to add users programmatically to a Team Project. What I found out to be the solution was this:
IGroupSecurityService gss = (IGroupSecurityService)objTFS.GetService(typeof(IGroupSecurityService));
Identity identity = gss.ReadIdentity(SearchFactor.AccountName, "Group name", QueryMembership.None);
gss.AddMemberToApplicationGroup(groupProject.Sid, member.Sid);
但这仅适用于 TFS 已知的组/用户.
But this only work for groups/users known to TFS.
我想向 TFS 添加一个 Windows 帐户
I want to add a Windows account to TFS
例如:
Windows 帐户名:TestTFS
Windows account name: TestTFS
密码:123456
然后以编程方式将 TestTFS 添加到 TFS.
Then add the TestTFS to TFS programmatically.
我知道有一个名为 TeamFoundation Administration Tool 的工具可以做到这一点,但我不想使用它.
I know there is a tool named TeamFoundation Administration Tool can do that, but I do not want to use it.
推荐答案
在 TFS2012 中,IGroupSecurityService
被标记为过时并替换为 IIdentityManagementService
.
In TFS2012, the IGroupSecurityService
was marked obsolete and replaced with IIdentityManagementService
.
您可以使用 IIdentityManagementService.ReadIdentity()
以及 IIdentityManagementService.AddMemberToApplicationGroup()
将 Windows 用户添加到 TFS 组,即使 TFS 还不知道这些 Windows 用户.
You can use IIdentityManagementService.ReadIdentity()
along with IIdentityManagementService.AddMemberToApplicationGroup()
to add Windows users to TFS groups, even if those Windows users are not known to TFS yet.
这是通过指定ReadIdentityOptions.IncludeReadFromSource
选项.
This is accomplished by specifying the ReadIdentityOptions.IncludeReadFromSource
option.
以下是在 FabrikamFiber
中将 Windows 用户 VSALM\Barry
添加到 Fabrikam Fiber Web 团队
(TFS 组)的示例团队项目,位于 http://vsalm:8080/tfs/FabrikamFiberCollection
服务器/集合中.
Below is an example of adding a Windows user VSALM\Barry
to the Fabrikam Fiber Web Team
(TFS Group), in the FabrikamFiber
Team Project, in the http://vsalm:8080/tfs/FabrikamFiberCollection
server/collection.
您需要添加对以下内容的引用:Microsoft.TeamFoundation.Client
和 Microsoft.TeamFoundation.Common
You will need to add references to: Microsoft.TeamFoundation.Client
and Microsoft.TeamFoundation.Common
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://vsalm:8080/tfs/FabrikamFiberCollection"));
var ims = tpc.GetService<IIdentityManagementService>();
var tfsGroupIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"[FabrikamFiber]\\Fabrikam Fiber Web Team",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
var userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"VSALM\\Barry",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
ims.AddMemberToApplicationGroup(tfsGroupIdentity.Descriptor, userIdentity.Descriptor);
}
}
}
这篇关于如何以编程方式将用户添加到 TFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!