Detecting TFS version/install folder from MSBuild

巧了我就是萌 提交于 2019-12-07 19:36:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!