How to find the path to tf.exe from MsBuild - tfs

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 :)

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=""$(VS100COMNTOOLS)..\IDE\tf.exe""/>
</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

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.

Related

PowerShell to set Check-in Policy

I'm looking for a way to set the check-in policy in TFS via PowerShell. Ideally, I'd traverse the entire TFS project collection/project hierarchy, and turn on the Work Item required for check-in policy. I've seen and tried this guy's solution: http://www.manasbhardwaj.net/set-checkin-policies-projects-team-foundation-server-using-powershell/, but it's not working. Microsoft.TeamFoundation.VersionControl.Controls.WorkItemPolicy can't be found, so this approach is for naught. I've already figured out how to traverse the hierarchy, but I can't find the magic to set the policy. Anyone?
TFS 2013, on-premise. Visual Studio 2015/2017.
Microsoft.TeamFoundation.VersionControl.Controls.dll still ships with VS 2015/VS 2017, but it has been removed the client OM DLLs from the GAC.
In VS 2015, you can find the DLL in C:\program files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer.
In VS 2017, you can find the DLL in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer.

TFS / Visual Studio Online build definition backup

Is there any way to get hold of a VSO build definition file, so it can be backed up / added to source control?
I've seen this question but tfpt doesn't appear to support connection to VSO (maybe I'm doing something wrong?)
tfpt builddefinition /dump <myproj> /collection:https://<myorg>.visualstudio.com/
TF31002: Unable to connect to this Team Foundation Server: https://<myorg>.visualstudio.com/
Thanks in advance.
Thanks to jessehouwing, and some further web searches, the following works:
tfpt builddefinition /dump "<projName>\<buildDefName>" /collection:https://<myOrg>.visualstudio.com/defaultcollection /filepath:<pathToBackup>
If you get this error:
Could not load file or assembly 'Microsoft.TeamFoundation.Build.Workflow, Version=12.0.0.0, Culture=neutral, PublicKeyTo
ken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
You need to copy Microsoft.TeamFoundation.Build.Workflow.dll from
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies
to
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools
(thanks to http://blogs.ripple-rock.com/richarderwin/2014/09/11/CompareTFSBuildDefinitions.aspx)

TFS Path for commandline tools to use in MSBuild

It it my understanding that it is still the simplest to use the <Exec \> MSBuild task and shell to TF.exe in order to TFS command line during MSBuild, especially if you don't want to create a dependency on custom build tasks or extension packs etc. (see Checkout from TFS with MSBuild)
Given that, what is the best path to use for tf.exe especially since different developers may have TFS2010 or TFS2012 mixed with VS2010 and VS2012 and also mixed with 64-bit workstations.
Is there parhaps a variable / path standard way to call the TF.exe command from MSBuild regardless of VS or TFS version?
You can see if a system is 64-bit by looking for the ProgramW6432environment variable.
And as long as users have chosen the default install path, TF.exe is still installed in the 32-bit part of Visual Studio even for VS2012. So the only thing you should need to look for is whether the user has 2012 or 2010 installed. That should be possible with the Exists condition:
<PropertyGroup>
<ProgramFiles32 Condition="$(ProgramW6432) != ''">$(PROGRAMFILES) (x86)</ProgramFiles32>
<ProgramFiles32 Condition="$(ProgramFiles32) == ''">$(PROGRAMFILES)</ProgramFiles32>
<VS10Dir>$(ProgramFiles32)\Microsoft Visual Studio 10.0</VS10Dir>
<VS11Dir>$(ProgramFiles32)\Microsoft Visual Studio 11.0</VS11Dir>
<TF Condition="Exists('$(VS10Dir)')">"$(VS10Dir)\Common7\IDE\TF.exe"</TF>
<TF Condition="Exists('$(VS11Dir)')">"$(VS11Dir)\Common7\IDE\TF.exe"</TF>
</PropertyGroup>
...
<Exec Command="$(TF) checkout ..."></Exec>
tbergstedt has a solution is likely more robust and can be adapted to other problems too. I did discover that there is a shortcut for this, since the TF.exe executable is also in the Developer Environment path $(DevEnvDir). See below:
<PropertyGroup>
<TfCommand>"$(DevEnvDir)\tf.exe"</TfCommand>
</PropertyGroup>

How to get tf.exe (TFS command line client)?

What's the minimum amount of software I need to install to get the 'tf.exe' program?
You need to install Team Explorer, it's best to install the version of Team Explorer that matches the version of TFS you are using e.g. if you're using TFS 2010 then install Team Explorer 2010.
2012 version http://www.microsoft.com/en-gb/download/details.aspx?id=30656
2013 version http://www.microsoft.com/en-us/download/details.aspx?id=40776
2019 version https://visualstudio.microsoft.com/downloads/#visual-studio-team-explorer-2019
You also might be interested in the TFS power tools. They add some extra command line features (using tfpt.exe) and also add some extra IDE features.
I'm in a virtual machine, and am trying to keep my VHD as small as possible, so I find Team Explorer is a really heavyweight solution (300+ MB install). As an alternative, I've had some luck copying a minimal set of EXEs/DLLs from a Team Explorer installation to a clean machine (.NET 4.0 is still required, of course).
I've only tried a handful of operations so far, but this set of files (about 8.5 MB) has been enough to get basic source-control functionality via tf.exe:
TF.exe
TF.exe.config
Microsoft.TeamFoundation.dll
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundation.Common.Library.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Microsoft.TeamFoundation.VersionControl.Common.dll
Microsoft.TeamFoundation.VersionControl.Controls.dll
(It should go without saying that this is a completely unsupported solution, and it doesn't free you from the normal TFS licensing requirements.)
Depending on the operations you perform, you may find that additional DLLs are required. Fortunately, tf.exe will produce a nice error message telling you exactly which ones are missing.
For Visual Studio 2017 & 2019, it can be found here :
-Replace {YEAR} by the appropriate year ("2017", "2019").
-Replace {EDITION} by the appropriate edition name ("Enterprise", "Professional", or "Community")
C:\Program Files (x86)\Microsoft Visual Studio\{YEAR}\{EDITION}\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe
For Visual Studio 2022, it can be found here :
C:\Program Files\Microsoft Visual Studio\2022\{EDITION}\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe
There is a Java TFS client in the Team Explorer Everywhere installation (together with an Eclipse plugin). Look at http://www.microsoft.com/en-us/download/details.aspx?id=30661
For reference: these are the required DLLs for Visual Studio 2017 (as did #ijprest for the VS 2010)
TF.exe
TF.exe.config
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundation.Core.WebApi.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Microsoft.TeamFoundation.VersionControl.Common.dll
Microsoft.TeamFoundation.VersionControl.Controls.dll
Microsoft.VisualStudio.Services.Client.Interactive.dll
Microsoft.VisualStudio.Services.Common.dll
Microsoft.VisualStudio.Services.WebApi.dll
They will be in my base VM image. I'm going to use it to pull the latest deployment scripts from VC to a temporary local workspace folder when installing a new server.
tf workspace /new ...
tf workfold /map ...
tf get "%WorkSpaceLocalFolder%" /recursive
tf workfold /unmap
tf workspace /delete
<run deployment scripts from "%WorkSpaceLocalFolder%" >
rmdir "%WorkSpaceLocalFolder%"
(Sorry to post this as an answer, but I don't have enough reputation to comment, which I believe it should have been)
The tf.exe command line is included in the VSTS agent package in folder externals\vstsom.
You can also try TFS CLI for Node.js which is a cross-platform CLI for Microsoft Team Foundation Server and Visual Studio Team Services.
Visual Studio 2017 Team Explorer
According to https://blogs.msdn.microsoft.com/bharry/2017/04/05/team-explorer-for-tfs-2017/ you can now download it separately from Visual Studio via this link:
https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=TeamExplorer&rel=15
Following on from the earlier answers above but based on a VS 2019 install ;
I needed to run "tf git permission" commands, and copied the following files from:
C:\Program Files (x86)\Microsoft Visual Studio\2019\TeamExplorer\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundation.Core.WebApi.dll
Microsoft.TeamFoundation.Diff.dll
Microsoft.TeamFoundation.Git.Client.dll
Microsoft.TeamFoundation.Git.Contracts.dll
Microsoft.TeamFoundation.Git.Controls.dll
Microsoft.TeamFoundation.Git.CoreServices.dll
Microsoft.TeamFoundation.Git.dll
Microsoft.TeamFoundation.Git.Graph.dll
Microsoft.TeamFoundation.Git.HostingProvider.AzureDevOps.dll
Microsoft.TeamFoundation.Git.HostingProvider.GitHub.dll
Microsoft.TeamFoundation.Git.HostingProvider.GitHub.imagemanifest
Microsoft.TeamFoundation.Git.Provider.dll
Microsoft.TeamFoundation.SourceControl.WebApi.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Microsoft.TeamFoundation.VersionControl.Common.dll
Microsoft.TeamFoundation.VersionControl.Common.Integration.dll
Microsoft.TeamFoundation.VersionControl.Controls.dll
Microsoft.VisualStudio.Services.Client.Interactive.dll
Microsoft.VisualStudio.Services.Common.dll
Microsoft.VisualStudio.Services.WebApi.dll
TF.exe
TF.exe.config

TFS command line client default location

If I'm using the TFS command line client is it always located # <drive>:\Program Files\Microsoft Visual Studio 8\Common7\IDE? I'm referencing this page.
Nope, depends on VS version installed (and don't forget 64 bit machines too)
For reference only,My default location is
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
vs2010,win7,64 bit
No it is not. E.g. on my machine it is under c:\VS10\Common7\IDE. You can use environment variables VS100COMNTOOLS (for VS 2010) and VS90COMNTOOLS (for VS 2008). The location of the tfs command line tools would be
"%VS100COMNTOOLS%\..\IDE\tf.exe"
-- for VS 2010
"%VS00COMNTOOLS%\..\IDE\tf.exe"
-- for VS 2008
In VS2008, tf.exe will be available under C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

Resources