Find an installed tf.exe, then run it with the command-line parameters specified.
Posted by jpluimers on 2015/04/30
Often I want to execute a TF.exe from the console, but don’t have the Visual Studio environment variables setup. Most of the times I want to run TF.exe from the most current Visual Studio installation, hence this TF.bat file figures out the location of it, then runs with the parameters passed to TF.bat:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal | |
| IF /I %PROCESSOR_ARCHITECTURE% == amd64 goto :x64 | |
| IF /I %PROCESSOR_ARCHITEW6432% == amd64 goto :x64 | |
| goto :x86 | |
| :x64 | |
| :: OS is 64bit | |
| set vsBaseKey=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\ | |
| goto :findTF | |
| :x86 | |
| :: OS is 32bit | |
| set vsBaseKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\ | |
| goto :findTF | |
| :findTF | |
| :: https://gist.github.com/rojepp/634908 | |
| :: http://stackoverflow.com/questions/5369528/windows-batch-reg-query-key-value-to-a-variable-but-do-not-display-error-if-key | |
| set SupportedVisualStudioVersions=8.0, 9.0, 10.0, 11.0, 12.0, 13.0 | |
| for %%v in (%SupportedVisualStudioVersions%) do ( | |
| for /f "usebackq tokens=2* delims= " %%c in (`reg query "%vsBaseKey%%%v" /v InstallDir 2^>NUL`) do ( | |
| set tfExe=%%dtf.exe | |
| ) | |
| ) | |
| if "%tfExe%"=="" ( echo no TF.exe found ) else ( | |
| if not exist "%tfExe%" echo not found: "%tfExe%" | |
| if exist "%tfExe%" "%tfExe%" %* | |
| ) | |
| endlocal |
A few notes:
- I wasn’t sure from which Visual Studio version TF.exe was supported. I thought Visual Studio 2005 or 2008, but got confirmed it was Visual Studio 2005 (a.k.a. 8) by Love the elegance of F#. This code looks for the TFS Command line tool and returns Somepath or None.
- The Visual Studio names and version numbers are a mess, so I usually first look at the Wikipedia Microsoft Visual Studio History table.
- The same holds for many other numbers and registry paths.INFO: Visual Studio version numbers is of great help here.
- The base registry path depends if you are running on an x64 or x86 system I used the PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432 environment variables to detect which bitness was running as described in HOWTO: Detect Process Bitness – David Wang – MSDN Blogs (I blogged about that before: Windows batch file to set ProgramFilesX86 directory for 32-bit program files on x86 and x64 systems via: Stack Overflow).
- Since I have no VM that has all these Visual Studio installations installed, reg query usually gives an error message. The 2^>NUL trick gets around that: Windows Batch: reg query key value to a variable but do not display error if key doesn’t exist – Stack Overflow.
–jeroen
via: Find an installed tf.exe, then run it with the command-line parameters specified.. PS:
This post supercedes using tf to list the workspaces for the current directory in Team Foundation System « The Wiert Corner – irregular stream of stuff.






tf: show changeset details on the console « The Wiert Corner – irregular stream of stuff said
[…] above tf-show-changeset-details-on-console.bat batch file uses tf.bat that hunts for the location of […]