Team Foundation Version Control Scripts and Command Files
You can assemble and perform multiple Team Foundation version control commands at the command prompt by redirecting a command to a command file or by including them in a batch file or script.
A command file enables you to perform multiple commands more quickly than a series of individual commands because a command file reuses a single connection to the application-tier server and creates only one instance of tf.
The command file switch is the at sign character (@). To call a command file using tf, use the following syntax:
tf @commandfilename.tfc argument1 argument2 …
The following example instructs Team Foundation to look in the file buildcommands.tfc for additional instructions. Supplied with the following input, this example gets the latest version of 314.cs from the Team Foundation version control server, checks it out in the workspace, branches it to c:\newbranch\, and commits the changes to the Team Foundation version control server.
c:\projects>tf @buildcommands.tfc 314.cs c:\newbranch\
Contents of buildcommands.tfc:
get %1 checkout %1 branch %1 %2 checkin
When the command file switch is specified, you can include as many arguments as you want. Arguments provide values to the commands in your command file. Standard arguments include file names, paths, login names, comments, and versionspecs.
Suppressing and Restoring Command Prompt Interactivity
By default, command files are non-interactive. Many commands, such as undo, use the interactive mode as a default when performed using the command line application, tf. When you are performing individual Team Foundation commands, you can include the /noprompt flag to bypass warning messages and perform such commands in a non-interactive manner. In command files, /noprompt is implicitly included.
Sample Command File
When you perform the following command, Team Foundation parses BuildProject.tfc and creates the workspace HumongousInsurance 2.3, gets the latest version of the HumongousInsurance project, branches off the new version in Humongous Insurance V2.3, and labels the new version. For each new build, she just runs the command file with the project name, and the new build’s version number and local directory.
c:\>tf @BuildProject.tfc HumongousInsurance 2.3 c:\projects
Contents of BuildProject.tfc:
cd %3 rem Change the current directory from whatever it is to the project folder. workspace /new /s:TeamServer2 /user:UNO\juan %1BuildWS%2 rem Create a new workspace on the TeamServer2 server as user UNO\juan. rem Assign a name to the workspace that concatenates the first command line argument (%1) + "BuildWS" + the second command line argument (%2) get %1 /recursive rem retrieve the latest version of the first command line argument. branch %1 %1V%2 checkin /comment:"This is build v%2 of %1" label %1Build%2 /category:builds /comment:"%1 Build %2" %1V%2 workspace /delete %1BuildWorkspace%2