2

I wish to call the GetBuildProperties task from my MSBuild script run on TFS. However, this script can be run on either TFS 2010 or TFS 2013. Is there a way to detect the version of TFS that has launched an MSBuild Script? At the moment, I am getting around the problem like so:

  <PropertyGroup>
    <CurrentProgramFiles>$(ProgramW6432)</CurrentProgramFiles>
    <CurrentProgramFiles Condition="$(CurrentProgramFiles) == ''">$(ProgramFiles)</CurrentProgramFiles>
  </PropertyGroup>

  <PropertyGroup Condition="$(TeamFoundationServerUrl)!='' and Exists('$(CurrentProgramFiles)\Microsoft Team Foundation Server 2010')">
    <TeamBuildRefPath>$(CurrentProgramFiles)\Microsoft Team Foundation Server 2010\Tools</TeamBuildRefPath>
  </PropertyGroup>

  <PropertyGroup Condition="$(TeamFoundationServerUrl)!='' and Exists('$(CurrentProgramFiles)\Microsoft Team Foundation Server 12.0')">
    <TeamBuildRefPath>$(CurrentProgramFiles)\Microsoft Team="" Foundation Server 12.0\Tools</TeamBuildRefPath>
  </PropertyGroup>

  <UsingTask
    TaskName="Microsoft.TeamFoundation.Build.Tasks.GetBuildProperties"
    AssemblyFile="$(TeamBuildRefPath)\Microsoft.TeamFoundation.Build.ProcessComponents.dll"
    Condition="$(TeamFoundationServerUrl)!=''" />
1
  • Can you clarify if you need the TFS version or the Build Agent version? Commented Sep 2, 2014 at 6:09

1 Answer 1

2

Starting with TFS 2013 you have some interesting variables, not previously available TF_BUILD environment variables. So you can use TF_BUILD to know if you are using 2013, like this.

  <PropertyGroup>
      <IsTFS2013orHigher Condition="$(TF_BUILD)!=''>Yes</IsTFS2013orHigher>
  </PropertyGroup>

For the install path I would peek the Registry

  <PropertyGroup>
    <TFS2013InstallPath>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\TeamFoundationServer\12.0@InstallPath)</TFS2013InstallPath>
    <TFS2012InstallPath>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\TeamFoundationServer\11.0@InstallPath)</TFS2012InstallPath>
    <TFSInstallPath Condition="'$(TFS2013InstallPath)'!=''">$(TFS2013InstallPath)</TFSInstallPath>
    <TFSInstallPath Condition="'$(TFS2013InstallPath)'=='' and '$(TFS2012InstallPath)'!=''">$(TFS2012InstallPath)</TFSInstallPath>
  </PropertyGroup>
Sign up to request clarification or add additional context in comments.

7 Comments

That will however only tell you which version of TF Build is present. You can connect TF Build 2010 to TFS 2013 so your results may vary.
Correct, but the Q was about detecting local install, i.e. the TFS Build Agent version, to use a specific MSBuild Task.
The question does not specify the Build Agent version, only TFS. I would prefer the person who asked the question to clarify rather than making assumptions. 😊
Yes, the agent will be the same as the server (i.e. can be a mix of TFS2010 and TFS2013)... so I wish to be able to tell which. Thank you Giulio for your response, I think we cannot use the environment variables owing to support for older versions. The registry peaking is a really neat idea though!
Since you check the xaml file into the server in question why not just add a variable that you set in the file or in the build definition?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.