Wednesday, 18 July 2012

How to Download Code from TFS (Team Foundation Server) using .bat file?

Hello Guys

Below is the code to download code from TFS (Team Foundation Server) using command prompt or .bat file:

@echo off
:: variable declarations
::*********************************************************
set userName=Domain\UserName
set password=Password
set isCodeDownloadRequired=Y or N
set workSpacename=FOlder Name on your local drive
set tfsURL=URL of TFS
set tfsAddress=$/TFS Address
::*********************************************************
::**************************************************
:: Create work space and Download code from TFS
::**************************************************
:: check for existence of [Program Files(x86)]
if %isCodeDownloadRequired% == Y (GOTO DownloadTFSCode) ELSE (GOTO NotDownloadTFSCode)
:DownloadTFSCode
set EnvpathVS2010=%VS100COMNTOOLS%
::Creating path of Visual Studio Command Prompt
set PathToAppend=\VC\vcvarsall.bat" x86
set EnvpathVS2010=%EnvpathVS2010:\Common7\Tools\=%
set RootDirectory=%windir%
set RootDirectory=%windir:\Windows=%
set FinalPath="%EnvpathVS2010%%PathToAppend%
call %FinalPath%
cd\
%RootDirectory%
::Create Directory Application_App_Checkout
md Application_App_Checkout
::Into Directory Application_App_Checkout
cd Application_App_Checkout
tf workspace /delete %workSpacename% /noprompt
tf workspace /new %workSpacename% /noprompt /collection:%tfsURL% /login:%userName%,%password%
tf.exe get %tfsAddress% /recursive /login:%userName%,%password%
GOTO End
:NotDownloadTFSCode
echo "User does not wish to download latest code from TFS."
Pause
GOTO End
End Local

No comments:

Post a Comment