Team Foundation 版本控制脚本和命令文件

更新:2007 年 11 月

通过将命令重定向到命令文件或者将命令包含在批处理文件或脚本中,可以在命令提示处汇编并执行多个 Team Foundation 版本控制 命令。

命令文件:创建命令组

与分别执行一系列命令相比,命令文件使您可以更快速地执行多个命令,因为命令文件重用到应用层服务器的单个连接,并且只创建 tf 的一个实例。

命令文件开关是 @ 符。若要使用 tf 调用命令文件,请使用下面的语法:

tf @commandfilename.tfc argument1 argument2 …

下面的示例指示 Team Foundation 在文件 buildcommands.tfc 中查找其他指令。在提供以下输入的情况下,此示例从 Team Foundation 版本控制 服务器获取 314.cs 的最新版本,然后在工作区中将该版本签出,并将该版本分支到 c:\newbranch\,最后将这些更改提交给 Team Foundation 版本控制 服务器。

c:\projects>tf @buildcommands.tfc 314.cs c:\newbranch\

buildcommands.tfc 的内容如下:

get %1
checkout %1
branch %1 %2
checkin

在指定命令文件开关后,可以根据需要包含任意多个参数。参数为命令文件中的命令提供值。标准参数包括文件名、路径、登录名、注释和版本规范。

以交互方式取消和还原命令提示

默认情况下,命令文件是非交互式的。许多命令(如 undo)在使用命令行应用程序 tf 执行时,默认情况下使用交互模式。在执行单个 Team Foundation 命令时,可以包含 /noprompt 标志以跳过警告消息,并以非交互方式执行此类命令。在命令文件中,隐式包含 /noprompt

命令文件示例

在执行以下命令时,Team Foundation 将分析 BuildProject.tfc 并创建工作区 HumongousInsurance 2.3,然后获取 HumongousInsurance 项目的最新版本并在 Humongous Insurance V2.3 中分支出新版本,最后为该新版本附加标签。对于每个新版本,它只运行包含项目名称、新版本的版本号和本地目录的命令文件。

c:\>tf @BuildProject.tfc HumongousInsurance 2.3 c:\projects 

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

请参见

概念

信息性命令

参考

命令行选项

命令行语法 (Team System)

其他资源

Tf 命令行实用工具命令