MSBuild-无法读取目标中的属性

时间:2019-06-26 11:09:24

标签: msbuild msbuild-propertygroup

我正在更新构建目标,以在两个单独的位置中查找要在构建期间运行的.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>

1 个答案:

答案 0 :(得分:0)

两项工作对我来说都很棒。 但是我使用了Visual Studio 2017附带的msbuild。(/ c / Program Files(x86)/ Microsoft Visual Studio / 2017 / Professional / MSBuild / 15.0 / bin / msbuild.exe)

所以也许您使用的是真正的旧版本?

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

相关问题