30

I have an MsBuild file which shells out to TFS using tf.exe for a few things. Unfortunately the tf.exe file has been installed to different locations on the developer PCs and the build server.

I could really do with a way of detecting where the tf.exe file is located within my script in the same way you can do $(MSBuildExtensionsPath32) etc. Is this possible?

Thanks as always :)

Chris Surfleet
  • 2,462
  • 4
  • 28
  • 40

2 Answers2

41

Does the environment variable VS100COMNTOOLS point to the correct path for visual studio? E.g. VS100COMNTOOLS=C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\

So then all you need is $(VS100COMNTOOLS)..\IDE

<Target Name="Build">
   <Exec Command="&quot;$(VS100COMNTOOLS)..\IDE\tf.exe&quot;"/>
</Target>

or however you want to tidy it up.

The environment variable changes depending on the version of Visual Studio:

  • %VS110COMNTOOLS% - Visual Studio 2012
  • %VS120COMNTOOLS% - Visual Studio 2013
  • %VS140COMNTOOLS% - Visual Studio 2015
James Woolfenden
  • 6,498
  • 33
  • 53
  • 1
    Not sure what changed, but my tf.exe is not located in the Tools folder, but the IDE folder. – Ben Sep 18 '13 at 15:59
  • This is where mine is. C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE – sam yi Jan 15 '14 at 17:54
  • That's the path you get from the statement. Hence the ..\ide bit. – James Woolfenden Jan 15 '14 at 19:55
  • 1
    NB: As of VS2017 (at least, certain editions), this environment variable no longer exists by default, and https://github.com/Microsoft/vsts-vscode/issues/269. However, you can create `VS150COMNTOOLS` by running: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/how-to-set-environment-variables-for-the-visual-studio-command-line – JohnLBevan Dec 15 '17 at 14:37
15

Seems they changed location again in Visual Studio 2017. It was not in any of the above locations on my machine.

I found TF.exe instead at:

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

(Some users may find in the Professional folder instead of Enterprise folder: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe)

Apparently the environment variable is no longer set by default in VS 2017.

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
BautaBear
  • 394
  • 3
  • 9
  • 2
    Similarly, for me it was "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe" ... However, Rider says "the specified path does not lead to a valid TF executable" – Mikal Madsen Oct 25 '17 at 11:05
  • @MikalMadsen +1 Same Issue – Michal Ciechan Nov 14 '17 at 09:19