zoukankan      html  css  js  c++  java
  • TFS团队项目操作

    本项目主要的功能是添加和删除团队项目集合、添加和删除团队项目以及向团队项目中添加用户。

    一、  添加和删除团队项目集合

    微软提供了专门用于添加和删除团队项目集合的API,使得我们的工作事半功倍。

    1、   创建团队项目集合

    这是微软提供的创建团队项目集合的API:

     1 Namespace: Microsoft.TeamFoundation.Framework.Client
    2 Assembly: Microsoft.TeamFoundation.Client (inMicrosoft.TeamFoundation.Client.dll)
    3
    4 ServicingJobDetailQueueCreateCollection(
    5
    6 string name,
    7
    8 string description,
    9
    10 bool isDefault,
    11
    12 string virtualDirectory,
    13
    14 TeamFoundationServiceHostStatusstate,
    15
    16 IDictionary<string, string>servicingTokens
    17
    18 )



     示例代码:

     1 public static bool CreateTeamprojectSet(stringprojectsetName,string discription)
    2
    3 {
    4
    5 List<ADominModel> ads = ADominDAL.GetAdominModels();
    6
    7 ADominModelad = ads[0];
    8
    9
    10
    11 stringserverUrl = @"http://" +ad.AdominIpAddress + ":8080/tfs";
    12
    13 stringcollectionName = projectsetName;
    14
    15 stringsqlConnectionString = "DataSource=SPMSERVER;Integrated Security=True;";
    16
    17 NetworkCredentialcredential = new NetworkCredential(ad.AdominSuperUser,ad.AdominPassWord, ad.AdominName);
    18
    19 TfsConfigurationServerTfs = new TfsConfigurationServer(new Uri(serverUrl),(ICredentials)credential);
    20
    21 ITeamProjectCollectionServicetpcService = Tfs.GetService<ITeamProjectCollectionService>();
    22
    23 Dictionary<string, string>servicingTokens = new Dictionary<string, string>();
    24
    25 servicingTokens.Add("SharePointAction", "None"); //不配置sharepoint
    26
    27 servicingTokens.Add("ReportingAction", "None"); //不设置报表服务
    28
    29 try
    30
    31 {
    32
    33 ServicingJobDetailtpcJob = tpcService.QueueCreateCollection(
    34
    35 collectionName, // 团队项目集合名称
    36
    37 discription, // 说明
    38
    39 false, // 是否为默认的团队项目集合
    40
    41 string.Format("~/{0}/",collectionName), //虚拟目录
    42
    43 TeamFoundationServiceHostStatus.Started, //初始状态
    44
    45 servicingTokens, //服务口令
    46
    47 sqlConnectionString, // 数据库连接字符窜 null, // 默认连接字符窜
    48
    49 null //数据库分类connection strings
    50
    51 )
    52
    53 TeamProjectCollectiontpc = tpcService.WaitForCollectionServicingToComplete(tpcJob);
    54
    55 returntrue;
    56
    57 }
    58
    59 catch(CollectionPropertyException ex)
    60
    61 {
    62
    63 throwex ;
    64
    65 }
    66
    67 catch(Exception ex)
    68
    69 {
    70
    71 throwex;
    72
    73 }
    74
    75 }
    76
    77



    2、   删除团队项目集合

    这是微软提供的删除团队项目集合的API:

    Namespace: Microsoft.TeamFoundation.Framework.Client

    Assembly: Microsoft.TeamFoundation.Client (inMicrosoft.TeamFoundation.Client.dll)

    ServicingJobDetailQueueDetachCollection(

    Guid collectionId,

    IDictionary<string, string>servicingTokens,

    string collectionStoppedMessage,

    out string detachedConnectionString

    )



    示例代码:

    public static bool DeleteCollection(stringcollectionName)

    {

    List<ADominModel> ads = ADominDAL.GetAdominModels();

    ADominModelad = ads[0];

    stringserverUrl = @"http://" +ad.AdominIpAddress + ":8080/tfs";

    NetworkCredentialcredential = new NetworkCredential(ad.AdominSuperUser,ad.AdominPassWord, ad.AdominName);

    TfsConfigurationServerTfs = new TfsConfigurationServer(new Uri(serverUrl),(ICredentials)credential);

    ITeamProjectCollectionServicetpcService = Tfs.GetService<ITeamProjectCollectionService>();

    Dictionary<string, string>servicingTokens = new Dictionary<string, string>();

    servicingTokens.Add("SharePointAction", "None"); //不配置sharepoint

    servicingTokens.Add("ReportingAction", "None"); //不设置报表服务

    TeamProjectCollectiondelCollection = GetCollection(collectionName);

    stringvirtualDirectory = delCollection.VirtualDirectory;

    stringconnectString;



    try

    {

    ServicingJobDetailtpcJob = tpcService.QueueDetachCollection(delCollection, servicingTokens, "stop", outconnectString);

    if(DeleteDatabase(collectionName))

    return true;

    }

    catch(Exception ex)

    {

    Console.WriteLine(ex);

    }

    connectString = "";

    returnfalse;

    }







    二、  添加和删除团队项目

    由于微软未提供这方面的API,但是另外提供了一个tfpt

    (下载地址)要创建和删除团队项目必须使用tfpt,考虑到每个客户端都要安装tfpt是不现实的,所以我们将tfpt安装在服务器上,通过webservice来调用tfpt从而实现其功能。这样设计还有一个好处:由于在Team Foundation Server(TFS)上只有系统管理员才能创建项目,故只要将部署Webservice的那台机器添加到TFS的系统管理员中就可以了,这样也方便各个平台的扩展。

    下面先介绍tfpt这个工具,其基本的命令如下:

    1.删除团队项目

    通过使用 TFSDeleteProject,可以将团队项目从 Team Foundation Server 中删除,前提是不再需要项目。此外,如果不成功的团队项目创建后仍未删除的组件,可以使用TFSDeleteProject 删除它们。(注意:TFSDeleteProject会永久地破坏团队项目,之后无法恢复它,你应该在使用 TFSDeleteProject 之前备份所有重要项目数据)

             

    可以在运行 团队资源管理器 的任何客户端计算机上的“<驱动器:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE”中找到TFSDeleteProject 命令行工具。

    所需权限

    若要使用 TFSDeleteProject 命令,您必须是“Team Foundation Administrators(Team Foundation 管理员)”安全组或“Project Administrators (项目管理员)”安全组的成员。有关更多信息,请参见TeamFoundation Server 权限Team Foundation Server 默认组、权限和角色

    删除团队项目命令:  

    TFSDeleteproject[/q] [/force] [/excludewss] /collection:URL TeamProjectName

    删除项目示意图如下:

    【参数列表】             

     

    选项

     
     

    说明

     
     

    /q

     
     

    可选。使用安静模式。不提示用户进行确认。

     
     

    /force

     
     

    可选。指定即使某些组件不能被删除,应继续删除过程。

     
     

    /excludewss

     
     

    可选。指定不删除与团队项目关联的 SharePoint 站点。指定此选项将维护现有的站点,以便其他团队项目可以继续使用它。

     
     

    /collection:URL

     
     

    必需。指定团队项目集合的 URI。必须对 URI 使用以下格式:http://ServerName:Port/VirtualDirectoryName/CollectionName

     

    如果不指定虚拟目录,则必须使用以下格式的 URI:

     

    http://ServerName:Port/CollectionName。

     
     

    TeamProjectName

     
     

    必需。项目的名称。如果名称包含空格,则将其置于引号中。

     

    2.  创建团队项目

    通过使用Createteamproject,在Team Foundation Server 中创建团队项目

     

    创建团队项目命令:

    tfpt createteamproject /collection:uri

                     /teamproject:"project name"

                     /processtemplate:"template name"

             [/sourcecontrol:New | None|Branch:branchpath]

                          [/log:"logfolder"]

                           [/validate]

                           [/verbose]

                           [/noreports]

                               [/noportal]

    【参数列表】

                                           

     

    选项

     
     

    说明

     
     

    /collection:URL

     
     

    必需。指定团队项目集合的 URI。必须对 URI 使用以下格式:http://ServerName:Port/VirtualDirectoryName/CollectionName

     

    如果不指定虚拟目录,则必须使用以下格式的 URI:

     

    http://ServerName:Port/CollectionName。

     
     

    /teamproject

     
     

    必需。需要创建的团队项目的名称。

     
     

    /processtemplate

     
     

    必需。创建项目所需要的模版名称。

     
     

    /sourcecontrol

     
     

    指定源控制选项:”New”表示创建一个新的树型控件源码;“None”表示创建一个新的项目不需要源码控件的支持;“Branch:branchpath” branch from an existing path on the TFS  server. For the Branch option: if the branchpath does not exist on the TFS  server, a list of existing paths are printed.

     
     

    /log

     
     

    可选。指定日志文件存放的路径

     
     

    /validate

     
     

    可选。指定用户输入进行验证。如果是特别用户只会做验证并且没有端口会改变。

     
     

    /verbose

     
     

    可选。开关的详细模式

     
     

    /noreports

     
     

    可选。指定的报告是否会被配置为项目

     
     

    / noportal

     
     

    可选。如果没有指定的项目门户网站或软件将被配置为项目。

     

    我们为大家提供一个简单的service(http://10.2.11.127/CreateTfs.asmx),有如下方法:

    只有将部署service的服务器添加到部署TFS的服务器后,远程调用方法,才可能实现功能,远程调用webservice时会在服务器上创建一个cmd进程:

              

     1   Process p = new Process();
    2
    3 //Process类有一个StartInfo属性,这是ProcessStartInfo类,包括一些属性和方法
    4
    5 p.StartInfo.FileName = "cmd.exe";
    6
    7 ////执行的命令及参数,cmdStr为Powershell脚本命令
    8
    9 p.StartInfo.Arguments = "/c " + cmdStr;
    10
    11 p.StartInfo.UseShellExecute = false; //关闭shell的使用
    12
    13 p.StartInfo.RedirectStandardInput = true;
    14
    15 p.StartInfo.RedirectStandardOutput = true;
    16
    17 p.StartInfo.RedirectStandardError= true;
    18
    19 p.StartInfo.CreateNoWindow = true;//设置不显示窗口
    20 p.Start(); //启动进程

    在cmd里面执行powershell脚本,从而创建或者删除团队项目。

  • 相关阅读:
    thinkphp nginx 上配置 并解决get获取到数据现象
    Linux下压缩某个文件夹(文件夹打包)
    Nginx下实现pathinfo及ThinkPHP的URL Rewrite模式支持
    SecureCRT超级终端使用说明
    redis 中文文档
    【Spring学习笔记-MVC-15】Spring MVC之异常处理
    【Spring学习笔记-MVC-14】Spring MVC对静态资源的访问
    【Spring学习笔记-MVC-13.2】Spring MVC之多文件上传
    【Spring学习笔记-MVC-13】Spring MVC之文件上传
    【Spring学习笔记-MVC-12】Spring MVC视图解析器之ResourceBundleViewResolver
  • 原文地址:https://www.cnblogs.com/hesitate/p/2227176.html
Copyright © 2011-2022 走看看