0

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

1 回答 1

0

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

所以也许你正在使用一个非常旧的版本?

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

于 2019-06-26T14:57:54.570 回答