【问题标题】:Detecting TFS version/install folder from MSBuild从 MSBuild 检测 TFS 版本/安装文件夹
【发布时间】:2014-09-01 11:08:11
【问题描述】:

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

  <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 版本还是 Build Agent 版本?

标签: tfs msbuild


【解决方案1】:

从 TFS 2013 开始,您有一些有趣的变量,以前没有 TF_BUILD environment variables。所以你可以用TF_BUILD来知道你用的是不是2013,像这样。

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

对于安装路径,我会查看注册表

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

【讨论】:

  • 然而,这只会告诉您存在哪个版本的 TF Build。您可以将 TF Build 2010 连接到 TFS 2013,因此您的结果可能会有所不同。
  • 正确,但 Q 是关于检测本地安装,即 TFS 构建代理版本,以使用特定的 MSBuild 任务。
  • 问题没有指定Build Agent版本,只有TFS。我希望提出问题的人澄清而不是做出假设。 ?
  • 是的,代理将与服务器相同(即可以是 TFS2010 和 TFS2013 的混合)......所以我希望能够分辨出哪个。感谢 Giulio 的回复,我认为由于对旧版本的支持,我们无法使用环境变量。不过,注册表峰值是一个非常好的主意!
  • 既然您将 xaml 文件检入到有问题的服务器中,为什么不直接添加您在文件或构建定义中设置的变量?
猜你喜欢
  • 2020-01-15
  • 1970-01-01
  • 2010-10-24
  • 1970-01-01
  • 1970-01-01
  • 2010-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多