从MSBuild检测TFS版本/安装文件夹 [英] Detecting TFS version/install folder from MSBuild

查看:82
本文介绍了从MSBuild检测TFS版本/安装文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望调用 GetBuildProperties 我的MSBuild脚本中的任务在TFS上运行. 但是,此脚本可以在TFS 2010或TFS 2013上运行. 有没有办法检测已启动MSBuild脚本的TFS版本?此刻,我正在解决这样的问题:

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)!=''" />

推荐答案

从TFS 2013开始,您有一些有趣的变量,以前没有提供

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>

这篇关于从MSBuild检测TFS版本/安装文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆