I have to create the same branches in every new team project

by Donovan Brown 17. December 2012 23:48

Problem:

I have to create the same branching structure in several team projects.  I would like a way to automate this process.

Solution:

Use the tf.exe and tfpt.exe command line tools in a batch file.

Explanation:

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.

@ECHO OFF

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
md %2\Main

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
Echo.
tf workspace /delete /noprompt temp

REM Remove the directories we created
rd %2 /s /q

REM Skip usage and just end
GOTO End

REM Show how to use the script
:Usage

Echo This batch file will create the default Main, Dev and Release branches
Echo for a team project.
Echo Requires:
Echo Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools
Echo.

Echo Usage:
Echo   createBraches collection teamProjectName
Echo.
Echo     collection = http://tfs:8080/tfs/myCollection
Echo     teamProjectName = the team project name in that collection 
Echo.
Echo   createBranches http://tfs:8080/tfs/sandboxcollection teamProjectName

:End

createBranches.cmd (1.67 kb)

Tags: , , , , ,

Work

I need to show TFS history of a file on the command line so I can redirect to a text file.

by Donovan Brown 13. September 2011 19:17

Problem:

When I run the tf history command from the command line it shows a dialog box.

Solution:

Add the /noprompt option to the TF History command. This will cause the output to be shown in the command window. You can then use DOS redirection to easily store the results in a text file.

For example:


tf history $/MyProject/Main/Source /recursive /noprompt /format:detailed /collection:http://MyTFS:8080/tfs/defaultcollection > history.txt

This will result in a new file called history.txt to be created in the working folder.

Explanation:

The key to not showing the dialog box is the /noprompt.  If you leave off the /noprompt you will be shown a dialog box.


The output redirection operator > is used to send the command output to somewhere other than the screen for example a text file.


> somefile.txt (If the file already exists it will be overwritten.)
>> somefile.txt (This will append a file. If the file does not already exist it will be created.)

Tags: , ,

Work

About the author

My name is Donovan Brown and I am a Technology Specialist for DevTools with Microsoft with a background in application development.  I also run one of the Nation’s fastest growing online registration sites for motorsports events DLBRacing.com.  When I am not writing software I race cars for fun.  DLBRacing.com has given me the opportunity to combine my two passions writing software and racing cars.

AdSense

Month List

AdSense