I have to create the same branching structure in several team projects. I would like a way to automate this process.
Use the tf.exe and tfpt.exe command line tools in a batch file.
Using the tf.exe and tfpt.exe command line tools you can preform the same task from the command line that you can preform in the IDE. Using tf.exe and tfpt.exe we can script the creation of the desired branching structure to speed up the process.
You can download the Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools from here.
The script below creates the Basic Branch Plan from the Visual Studio Team Foundation Server Branching and Merging Guide which you can download from here.
The script must by run from a Developer Command Prompt so that tf.exe and tfpt.exe can be found. Your other option is to update the environment variables for you machine to include the location of tf.exe and tfpt.exe in your path.
REM If they did not provide arguments show them how to
REM use this batch file
if "%1" == "" GOTO Usage
if "%2" == "" GOTO Usage
REM Create a temp workspace to create the branches in.
REM This will be deleted at the end
tf workspace /new /noprompt temp /collection:%1
REM Before you can create branches you must do a get latest
tf get $/%2
REM Create a main folder that will become the main branch of code
REM Add this folder to TFS
tf add %2\Main /noprompt
REM Check in the main folder
tf checkin /comment:"Adding main branch" /recursive /noprompt
REM Now start creating the other branches
REM main to dev
tf branch $/%2/Main $/%2/Dev /noget /checkin
REM main to release
tf branch $/%2/Main $/%2/Release /noget /checkin
REM We have to use tfpt from the power tools to convert
REM the folder to a branch so we get the new branch icons
REM in source control explorer
tfpt branches /convertToBranch /collection:%1 /recursive $/%2/Main
Echo Deleting temp workspace
tf workspace /delete /noprompt temp
REM Remove the directories we created
rd %2 /s /q
REM Skip usage and just end
REM Show how to use the script
Echo This batch file will create the default Main, Dev and Release branches
Echo for a team project.
Echo Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools
Echo createBraches collection teamProjectName
Echo collection = http://tfs:8080/tfs/myCollection
Echo teamProjectName = the team project name in that collection
Echo createBranches http://tfs:8080/tfs/sandboxcollection teamProjectName
createBranches.cmd (1.67 kb)