Scripting Team Project Creation in TFS2010

Grant Holliday’s blog

Senior Service Engineer, Microsoft Visual Studio Team Foundation Service

Scripting Team Project Creation in TFS2010

Rate This
  • Comments 7

In TFS2008 SP1 and the subsequent power tools release it was possible to create a team project from the command line. You can read Will-Peter’s detailed blog post on Creating a Team Project from the command line in TFS2008.

In TFS2010, it’s still not as good as we would like (it’s still client-based rather than server-based). But there’s one important difference – the feature has been rolled into the product and is no longer a power tool.

How to create a team project from the command line in TFS2010:

Create an XML file with the following contents and save it somewhere (e.g. C:\temp\pcw.xml). Substitute the highlighted as appropriate:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="ProjectCreationSettingsFileSchema.xsd">
       <TFSName>http://tfsserver:8080/tfs/DefaultCollection</TFSName>
       <LogFolder>c:\temp</LogFolder>
       <ProjectName>TestAgile2</ProjectName>
       <ProjectSiteEnabled>true</ProjectSiteEnabled>
       <ProjectSiteTitle>TestAgile2</ProjectSiteTitle>                 
       <ProjectSiteDescription>TestAgile2 project created from command line</ProjectSiteDescription>
       <SccCreateType>New</SccCreateType>
       <SccBranchFromPath></SccBranchFromPath>                
       <ProcessTemplateName>MSF for Agile Software Development v5.0</ProcessTemplateName>
</Project>

Once you have created the file, you need to prepare Visual Studio to be automated and trigger the automation from the command line.

  1. Open Visual Studio 2010
  2. Go to View > Team Explorer and make sure that the Team Explorer tab is active
  3. Close Visual Studio 2010
  4. Open a command prompt
  5. Type: CD /D %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE
  6. Type: devenv /command "File.BatchNewTeamProject C:\temp\pcw.xml"

At this point, Visual Studio will open and the Team Explorer tab will show “Connecting to server\collection…”.  In the background it’s actually creating the team project. You can verify this by looking for a txt file with the name of your project in the path you specified for LogFolder. (e.g. c:\temp\TestAgile2.txt)

Team Explorer connecting to server

Once the project has been created, you can select ‘Add existing team project’ and select it from the dialog.

Connect to Team Project dialog

If you want to create a fully-automated project provisioning system there are a few other things that you’ll need to do on top of creating the team project. Some of these things are:

  • Add users to TFS groups (Project Administrators, Contributors, Readers)
  • Add permissions in sharepoint
  • Add permissions in reporting services
  • A step in the right direction, I think. I would of cource prefer to have this capability included in the tfs api. Im just getting nervous the GUI part will limit the possibility to write a fully automated  project provissioning system, as it will require interaction wit the desktop.

    I have written some kind of a automated project provissioning system for TFS2008, with extensions to the TSF Warehouse. I have some post on the subject and the source at at http://mskold.blogspot.com/2009/08/team-system-administration-in_12.html

  • Would you please show me how to fully create a project, including the party of add adm, users, permissions?? And a sample code would be greate!

    But the topic is very nice!

  • Hi,

    I've read your article and tried it. It is very good but I want to create Tfs project without using IDE or using API from .aspx page.

    Could you help me in this regard?

    I'l' be very greatfull to you.

    Thanks & Regards

    Parveen Arora

  • @Parveen - Sorry Parveen, this is not possible - the only way to do it is using the IDE. There is no server-side project creation API that can be used in TFS2010.

  • Just posted this project on Codeplex: tfsprojprovisioner.codeplex.com

    Includes an assembly that hides BatchNewTeamProject behind a simple programmatic interface.

  • How would you construct the XML to add multiple projects?

  • @OldBassPlayer - You can't do multiple project creation with a single XML file. You need to run the command multiple times.

Page 1 of 1 (7 items)