问题
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:
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>
来源:https://stackoverflow.com/questions/25604478/detecting-tfs-version-install-folder-from-msbuild