以编程方式编写用于获取最新版本、签出和签入的 TFS 命令行脚本

我使用 WinXP、 VS2008和 TeamExplorer 连接到 TeamFoundationServer。

我需要以下的脚本(例如 BAT 文件脚本) :

  • 获取 TeamProject 中文件夹的最新版本。
  • 签出 TeamProject 中的文件夹文件。
  • 签入 TeamProject 中的文件夹文件。

我的 TFSProject 是 $/Arquitectura/Main/,映射到路径 C:\TFS\Arquitectura

有人有任何示例代码或建议吗?

94421 次浏览

Use tf.exe in the command line.

In the following examples, the %PathToIde% is usually on a path like this: %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE, or on Windows x64: %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE (depending on Visual Studio version and installation settings).

Example for get:

cd C:\TFS\Arquitectura
"%PathToIde%\TF.exe" get $/Arquitectura/Main /recursive

Example for checkout:

cd C:\TFS\Arquitectura
"%PathToIde%\TF.exe" checkout $/Arquitectura/Main /recursive

Example for checkin:

cd C:\TFS\Arquitectura
"%PathToIde%\TF.exe" checkin $/Arquitectura/Main /recursive

See for more information on the tf commandline.

"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe" get "$/ProjectName/Main" /force /recursive

get up to date code for Windows 7 64bit

"%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" get /recursive

This worked for me.

Update for VS2017

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe'

I tried the following piece of code in Powershell on Windows 10 64-bit and it worked for me:

cd C:\MyWorkspace
& "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe" get $/TFSFolderPath /recursive

Please note that the second line starts with an Ampersand (&), my code doesn't work without it, don't know the reason for it though.

Update for Visual Studio 2022

Create a Batch file for taking the latest version from TFS. Save this file with .bat extension

TakeLatest.bat

@echo off
title Project Builder
echo Taking Latest of All Projects which are listed here


cd /d %~dp0


call "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe" get /recursive


pause

Note: cd /d is your project folder location drive

For Visual Studio 2019

Update with this line into batch file ,

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe" get /recursive