Creating a new Team Project through the command line
As a Team Foundation Server administrator, you'll find yourself creating Team Projects over and over again. Team Project creation process can be scripted thanks to Team Foundation Server Power Tools. A Team Project is a container that can host multiple Teams and simplifies sharing of various artifacts such as processes, master backlogs, build definitions, and code artifacts. More often than not, you'll find that a new Team Project has been requested in ignorance simply because the requestor doesn't fully understand how multiple Teams can be accommodated in a Team Project. It is always beneficial to have a conversation to fully understand why a new Team Project has been requested. In this recipe, you'll learn how to script the creation of a new Team Project using the command line.
Getting ready
Microsoft Visual Studio Team Foundation Server Power Tools are available through the Visual Studio Gallery. Power Tools are a set of tools, enhancements, and command-line utilities that can make a TFS administrator more productive. Download and install the Power Tools by browsing to http://bit.ly/1jJkEmt:
Installing TFS Power Tools installs the command-line utility Tfpt.exe. Tfpt.exe is a companion tool to tf.exe that offers additional version control commands, Work Item tracking, and Team Project manipulation. Open up a new command line and type tfpt.exe /?
. If you do not see a list of available commands as shown in the following screenshot, the Power Tools haven't been installed correctly. Verify the installation before proceeding.
How to do it...
- Create a new folder
TFSCookbook\Chapter01
in theC:\ drive
. Copy the text as follows in Notepad and save it toC:\TFSCookbook\Chapter01
assettings.xml
:<?xml version="1.0" encoding="utf-8"?> <Project xmlns="ProjectCreationSettingsFileSchema.xsd"> <TFSName>http://tfs2015:8080/tfs</TFSName> <LogFolder>C:\TFSCookbook\Chapter01</LogFolder> <ProjectName>ScriptedTeamProject01</ProjectName> <ProjectReportsEnabled>true</ProjectReportsEnabled> <ProjectSiteEnabled>true</ProjectSiteEnabled> <ProjectSiteTitle>ScriptedTeamProject01</ProjectSiteTitle> <SccCreateType>New</SccCreateType> <ProcessTemplateName>Scrum</ProcessTemplateName> </Project>
- In command prompt run the following command:
tfpt createteamproject /settingsfile:"C:\TFSCookbook\Chapter01\settings.xml" /validate /verbose
- You should receive a message confirming whether the validation is successful. If not, check the error message against the information in the settings file:
- To create the Team Project, run the earlier command by removing the
/validate
switch.tfpt createteamproject /settingsfile:"C:\TfsCookbook\Chapter01\settings.xml" /verbose
- Wait for the Team Project creation process to complete.
Note
Note that
tfpt createteamproject
does not support scripting a new Team Project with Git as the source control repository.
How it works...
The Team Project creation command takes the settings.xml
file as an input; let's review the information that was provided in settings.xml
:
TFSName
: This tag is used to specify the connection details of the TFS Server where you want the new Team Project to be created.LogFolder
: This tag is used to specify the folder directory for the log file. This path should exist on the TFS application tier.ProjectName
: The Team Project name. If you specify a Team Project name that already exists, the Team Project creation process will fail during the validation process.ProjectReportsEnabled
: Certain default project reports are created as part of the Team Project creation process. This tags accepts a Boolean value; passfalse
to skip the default reports from being added.ProjectSiteEnabled
: If your Team Foundation Server installation has SharePoint services enabled, you can pass a value oftrue
in this tag to have a SharePoint Team site created for the new Team Project.ProjectSiteTitle
: This tag is ignored if the value ofProjectSiteEnabled
isfalse
. This tag is used to specify the name of the SharePoint Team site you have chosen to create as part of the Team Project creation process.SccCreateType
: If atrue
value is passed in this tag, a new TFVC source control is created, alternatively an existing TFS source control path can be passed to create a TFVC source control from the contents of the specified TFS path.ProcessTemplateName
: This tag is used to pass the name of the Process Template that the Team Project should be based on.Note
A list of all Process Templates available on your Team Foundation Server can be seen from Process Template Manager. To access Process Template Manager, open Visual Studio and connect to Team Foundation Server. From Team Explorer choose Settings. From the Settings view, click on Process Template Manager.
Now, let's review the createteamproject
command:
tfpt createteamproject /settingsfile:"C:\TFSCookbook\Chapter01\settings.xml" /validate /verbose
The /settingsfile
path is used to specify the location of the settings file. TFPT parses the settings file and triggers the Team Project creation process by connecting to the Team Foundation Server using the details specified in the settings file. The Team Project isn't created when the /validate
switch is used; the whole process is run as a validation to identify any potential issues. The /verbose
flag is used to log details of the operations being performed during this process. The verbose option can be very useful when troubleshooting issues.
There's more...
The tfpt.exe
command-line tools also provide many other useful commands. The two worth mentioning are addprojectportal
and addprojectreports
.
addprojectportal
: Over time, one may recognize the need for creating or moving the project portal. This command supports both operations in an existing Team Project.tfpt addprojectreports /collection:http://tfs2015:8080/tfs /teamproject:"Fabrikam" /processtemplate:"Scrum" /webapplication:"" /relativepath:"pathfromwebapp" /validate /verbose
addprojectreports
: The add reports operation creates the reports in the chosen Team Project. This command overwrites the reports if they already exist.tfpt addprojectreports /collection:"http://tfs2015:8080/tfs" / teamproject:"Fabrikam" /processtemplate:"Scrum" /validate /verbose