C# 如何使用API在TFS中将组从项目添加到区域?
我正在制作一个控制台应用程序,它接受用户输入来创建一个新区域。基于该名称,将生成组并将其放入项目中,并将其硬编码到应用程序中。到目前为止,以下代码将执行此操作:C# 如何使用API在TFS中将组从项目添加到区域?,c#,visual-studio,tfs,C#,Visual Studio,Tfs,我正在制作一个控制台应用程序,它接受用户输入来创建一个新区域。基于该名称,将生成组并将其放入项目中,并将其硬编码到应用程序中。到目前为止,以下代码将执行此操作: Project that all areas will be placed into -> Areas -> New area just created -> Security -> Groups -> Newly created gr
Project that all areas will be placed into
-> Areas
-> New area just created
-> Security
-> Groups
-> Newly created groups
但是,我也希望将这些团体安置在该地区本身:
Project that all areas will be placed into
-> Areas
-> New area just created
-> Security
-> Groups
-> Newly created groups
-> Security
-> Groups
-> Newly created groups
现在,当您查看该区域的安全性时,其中只有默认组,而不是我创建的组
我找不到任何关于通过API管理区域安全性的信息
public class AreaBuilder
{
static IIdentityManagementService _ims;
static List<TeamFoundationIdentity> m_groups = new List<TeamFoundationIdentity>();
static void Main(string[] args)
{
string projectName = "some_project";
string mainUri = "http://something:8080/tfs";
string collectionUri = "http://something:8080/tfs/some_collection";
Console.WriteLine("Enter the name of an area that you'd like to create: \n\n");
Console.Write("AreaBuilder> ");
string areaName = Console.ReadLine();
// Get the structure of the groups and their privileges
AreaStructure structure = new AreaStructure(areaName);
Dictionary<string, List<AreaStructure.Privileges>> groups = structure.getGroups();
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri));
VersionControlServer vcs = tpc.GetService<VersionControlServer>();
try
{
Microsoft.TeamFoundation.VersionControl.Client.TeamProject project = vcs.GetTeamProject(projectName);
IGroupSecurityService gss = tpc.GetService<IGroupSecurityService>();
foreach(string groupName in groups.Keys)
{
gss.CreateApplicationGroup(project.ArtifactUri.AbsoluteUri, groupName, null);
Console.WriteLine(groupName + " created.");
}
}
catch (Exception e)
{
Console.WriteLine("Could not create group: " + e.ToString());
}
WorkItemClassificationNode node = new WorkItemClassificationNode()
{
Name = areaName,
StructureType = TreeNodeStructureType.Area,
Children = new List<WorkItemClassificationNode>()
};
// Get the connection
VssConnection connection = new VssConnection(new Uri(collectionUri), new VssCredentials());
// Get the work item client
WorkItemTrackingHttpClient workItemTrackingClient = connection.
GetClient<WorkItemTrackingHttpClient>();
// Create the new area
WorkItemClassificationNode area = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(
node,
projectName,
TreeStructureGroup.Areas).Result;
// Get the project client
ProjectHttpClient projectClient = connection.GetClient<ProjectHttpClient>();
// Get the projects in the project client
IEnumerable<TeamProjectReference> projects = projectClient.GetProjects().Result;
Console.ReadLine();
}
}
公共类AreaBuilder
{
静态身份管理服务;
静态列表m_组=新列表();
静态void Main(字符串[]参数)
{
string projectName=“some_project”;
字符串mainUri=”http://something:8080/tfs";
字符串集合URI=”http://something:8080/tfs/some_collection";
WriteLine(“输入要创建的区域的名称:\n\n”);
控制台。写入(“AreaBuilder>”;
字符串areaName=Console.ReadLine();
//获取组的结构及其权限
AreaStructure结构=新的AreaStructure(areaName);
字典组=structure.getGroups();
TfsTeamProjectCollection tpc=新的TfsTeamProjectCollection(新Uri(collectionUri));
VersionControlServer vcs=tpc.GetService();
尝试
{
Microsoft.TeamFoundation.VersionControl.Client.TeamProject项目=vcs.GetTeamProject(项目名称);
IGroupSecurityService gss=tpc.GetService();
foreach(groups.Keys中的字符串groupName)
{
gss.CreateApplicationGroup(project.ArtifactUri.AbsoluteUri,groupName,null);
Console.WriteLine(groupName+“created”);
}
}
捕获(例外e)
{
Console.WriteLine(“无法创建组:+e.ToString());
}
WorkItemClassificationNode节点=新的WorkItemClassificationNode()
{
名称=区域名称,
StructureType=TreeNodeStructureType.Area,
Children=新列表()
};
//接通
VssConnection connection=新VssConnection(新Uri(collectionUri),新VssCredentials());
//获取工作项客户端
WorkItemTrackingTTPClient workItemTrackingClient=连接。
GetClient();
//创建新区域
WorkItemClassificationNode area=workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(
节点,
项目名称,
树结构(组区域)结果;
//获取项目客户
ProjectHttpClient projectClient=connection.GetClient();
//在项目客户机中获取项目
IEnumerable projects=projectClient.GetProjects().Result;
Console.ReadLine();
}
}
您似乎希望以编程方式将新创建的组添加到新创建的区域安全对话框中,然后授予该组的权限
遗憾的是,现在没有TFS ADK可供您以编程方式将组添加到区域安全性对话框。但是,为什么要先将新创建的组添加到“项目安全性”对话框中,然后再为其授予权限?您也可以直接授予权限,即使该组未显示在“区域安全”对话框中
您可以使用tfsseecurity
命令行为您完成工作,也可以使用tfsapi授予权限。使用
这篇博文还向您展示了如何使用API:。您还可以查看此示例,它显示了如何设置区域的权限:此外,要设置组的权限,您必须传递一个与您尝试允许/拒绝的权限相对应的int。但是,在中,它们缺少与“创建标记定义”、“删除此项目中的工作项”和“永久删除此项目中的工作项”权限相对应的整数。因此,我不知道如何将这些权限设置为project@JoshEvans首先,我为误会感到抱歉。更新了我的回复。谢谢Patrick,链接很棒。然而,你注意到我在上述评论中的问题了吗?@JoshEvans以前没有注意到这一点。对此不确定,您可以看看TracyZhang在这个问题上的回答,似乎您可以从相应的数据库中获取整数变量。尚未能够在区域级别为组设置权限。我读了你链接到的博客,看起来有些类已经过时了。我还看了一下,这似乎已经过时了。在过去的5年中,对于如何使用API在TFS中为组设置区域级权限,没有任何答案。