现在的位置: 首页 > 综合 > 正文

TFS团队项目操作

2014年03月24日 ⁄ 综合 ⁄ 共 7463字 ⁄ 字号 评论关闭

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

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

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

 

1、   创建团队项目集合

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

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

ServicingJobDetailQueueCreateCollection(

             string name,

             string description,

              bool isDefault,

             string virtualDirectory,

              TeamFoundationServiceHostStatusstate,

             IDictionary<string, string>servicingTokens

)

 

示例代码:

public static bool CreateTeamprojectSet(stringprojectsetName,string discription)

            {               

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

                ADominModelad = ads[0];

 

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

                stringcollectionName = projectsetName;

                stringsqlConnectionString = "DataSource=SPMSERVER;Integrated Security=True;";

                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"); //不设置报表服务

                try

                {

                    ServicingJobDetailtpcJob = tpcService.QueueCreateCollection(

                        collectionName,          // 团队项目集合名称

                        discription,             // 说明

                        false,                   //  是否为默认的团队项目集合

                        string.Format("~/{0}/",collectionName),  //虚拟目录

                        TeamFoundationServiceHostStatus.Started,  //初始状态

                        servicingTokens,                          //服务口令

                       sqlConnectionString,                     // 数据库连接字符窜                        null,                                   //  默认连接字符窜

                        null                          //数据库分类connection strings

                        )

                    TeamProjectCollectiontpc = tpcService.WaitForCollectionServicingToComplete(tpcJob);

                    returntrue;

                }

                catch(CollectionPropertyException ex)

                {

                    throwex ;

                }

                catch(Exception ex)

                {

                    throwex;

                }

            }

 

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进程:

            Process p = new Process();

              //Process类有一个StartInfo属性,这是ProcessStartInfo类,包括一些属性和方法

           p.StartInfo.FileName = "cmd.exe";

                ////执行的命令及参数,cmdStr为Powershell脚本命令

                p.StartInfo.Arguments = "/c " + cmdStr;

                p.StartInfo.UseShellExecute = false; //关闭shell的使用

               p.StartInfo.RedirectStandardInput = true;

               p.StartInfo.RedirectStandardOutput = true;

                p.StartInfo.RedirectStandardError= true;

                p.StartInfo.CreateNoWindow = true;//设置不显示窗口

                p.Start(); //启动进程

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

 

抱歉!评论已关闭.