【问题标题】:MSBuild - Can't read a Property in a TargetMSBuild - 无法读取目标中的属性
【发布时间】:2019-06-26 11:09:24
【问题描述】:

我正在更新构建目标,以便在构建期间在两个单独的位置查找要运行的 .exe。我创建了一个简单的测试项目来测试条件任务、属性组等,但无法弄清楚如何让我的 PropertyGroup 在使用它的目标之外 - 这是它在我想要的原始目标中的设置方式编辑。

这有效(目标内的属性组):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

  <Target Name="EmitCustomMessage" AfterTargets="Build">

    <PropertyGroup>
      <tryPath1>C:\tmp\BuildTest\LocationA\the_file.txt</tryPath1>
      <tryPath2>C:\tmp\BuildTest\LocationB\the_file.txt</tryPath2>
    </PropertyGroup>

    <PropertyGroup Condition="Exists('$(tryPath1)')">
      <UsePath>$(tryPath1)</UsePath>
    </PropertyGroup>

    <PropertyGroup Condition="Exists('$(tryPath2)')">
      <UsePath>$(tryPath2)</UsePath>
    </PropertyGroup>

    <Message Importance="high" Text="Exec at location [$(UsePath)]" />

  </Target>

</Project>

这不是 - $(UsePath) 始终为空:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

  <PropertyGroup>
    <tryPath1>C:\tmp\BuildTest\LocationA\the_file.txt</tryPath1>
    <tryPath2>C:\tmp\BuildTest\LocationB\the_file.txt</tryPath2>
  </PropertyGroup>

  <PropertyGroup Condition="Exists('$(tryPath1)')">
    <UsePath>$(tryPath1)</UsePath>
  </PropertyGroup>

  <PropertyGroup Condition="Exists('$(tryPath2)')">
    <UsePath>$(tryPath2)</UsePath>
  </PropertyGroup>

  <Target Name="EmitCustomMessage" AfterTargets="Build">

    <Message Importance="high" Text="Exec at location [$(UsePath)]" />

  </Target>

</Project>

【问题讨论】:

    标签: msbuild msbuild-propertygroup


    【解决方案1】:

    两者都适合我。 但是我使用了 Visual Studio 2017 附带的 msbuild。(/c/Program Files (x86)/Microsoft Visual Studio/2017/Professional/MSBuild/15.0/bin/msbuild.exe)

    那么也许您使用的是一个非常旧的版本?

    我还注意到您正在使用 ToolsVersion="3.5",您也应该提高它。那是古老的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 2021-08-04
      相关资源
      最近更新 更多