如何以编程方式将用户添加到 TFS
我想以编程方式将用户添加到团队项目中。我发现的解决方案是这样的:
IGroupSecurityService gss = (IGroupSecurityService)objTFS.GetService(typeof(IGroupSecurityService));
Identity identity = gss.ReadIdentity(SearchFactor.AccountName, "Group name", QueryMembership.None);
gss.AddMemberToApplicationGroup(groupProject.Sid, member.Sid);
但这仅适用于 TFS 已知的组/用户。
我想将 Windows 帐户添加到 TFS
例如:
Windows 帐户名称:TestTFS
密码:123456
然后以编程方式将 TestTFS 添加到 TFS。
我知道有一个名为 TeamFoundation Administration Tool 的工具可以做到这一点,但我不想使用它。
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);
But this only work for groups/users known to TFS.
I want to add a Windows account to TFS
For example:
Windows account name: TestTFS
Password:123456
Then add the TestTFS to TFS programmatically.
I know there is a tool named TeamFoundation Administration Tool can do that, but I do not want to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 TFS2012 中,
IGroupSecurityService
被标记为过时,并替换为IIdentityManagementService
。您可以使用
IIdentityManagementService.ReadIdentity()
以及IIdentityManagementService.AddMemberToApplicationGroup()
将 Windows 用户添加到 TFS 组,即使 TFS 尚不知道这些 Windows 用户。这是通过指定
ReadIdentityOptions 来完成的。 IncludeReadFromSource
选项。以下是将 Windows 用户
VSALM\Barry
添加到FabrikamFiber
团队项目中的Fabrikam Fiber Web 团队
(TFS 组)的示例,在http://vsalm:8080/tfs/FabrikamFiberCollection
服务器/集合中。您需要添加对:
Microsoft.TeamFoundation.Client
和Microsoft.TeamFoundation.Common
的引用In TFS2012, the
IGroupSecurityService
was marked obsolete and replaced withIIdentityManagementService
.You can use
IIdentityManagementService.ReadIdentity()
along withIIdentityManagementService.AddMemberToApplicationGroup()
to add Windows users to TFS groups, even if those Windows users are not known to TFS yet.This is accomplished by specifying the
ReadIdentityOptions.IncludeReadFromSource
option.Below is an example of adding a Windows user
VSALM\Barry
to theFabrikam Fiber Web Team
(TFS Group), in theFabrikamFiber
Team Project, in thehttp://vsalm:8080/tfs/FabrikamFiberCollection
server/collection.You will need to add references to:
Microsoft.TeamFoundation.Client
andMicrosoft.TeamFoundation.Common
我遇到了同样的问题,最后以下代码起作用了
命名空间:
using System.Security.Principal;
I had the same issue, finally following code worked
Namespace :
using System.Security.Principal;
为了通过 TFS API 执行此操作,您需要访问 2 个级别的信息。
您要添加的用户的sid,
您要添加用户的组的sid
=>您在帖子中显示的代码将获取您想要将用户添加到的组的 id。
我找到了 2 个包含示例代码的链接,我认为对您有帮助,
http://www.koders.com/csharp/fid950BA08A78C801F46B18D196597CBB40E2E2B29D.aspx
tfs管理工具的源代码:http://tfsadmin.codeplex.com/SourceControl/changeset/view/83047#1591025
In order to perform this operation via the TFS API, you need access to 2 levels of information.
The sid of the user you want to add,
The sid of the group you want to add the user to
=> The code you have shown in your post will get you the id of the group you want to add the user to.
I found 2 links with sample code i think can be helpful to you,
http://www.koders.com/csharp/fid950BA08A78C801F46B18D196597CBB40E2E2B29D.aspx
Source code of the tfs admin tool: http://tfsadmin.codeplex.com/SourceControl/changeset/view/83047#1591025