共用方式為


Team Foundation 版本控制指令碼和命令檔

更新:2007 年 11 月

您可以在命令提示字元下組合並執行多重 Team Foundation 版本控制命令,方法是將命令重新導向至命令檔 (Command File),或將這些命令納入批次 (Batch) 檔或指令碼。

命令檔:建立命令群組

命令檔可讓您執行多重命令,而且執行速度會比執行一連串個別的命令要快,因為命令檔會重複使用應用程式層伺服器的單一連接,並僅建立 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 旗標來略過警告訊息並以非互動式方式執行這類命令。在命令檔 (Command File) 中,隱含包含 /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 命令列公用程式命令