0

I'm updating a build target to look in two separate location for an .exe to run during the build. I've created a simple test project to test the conditional tasks, property groups, etc. but can't work out how to have my PropertyGroup outside the Target that uses it - this is the way it's setup in the original target I want to edit.

This works (property groups inside the target):

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

This does not - $(UsePath) is always empty:

<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>
newcube
  • 113
  • 7

1 Answers1

0

Both work great for me. But I used msbuild that came with Visual Studio 2017. (/c/Program Files (x86)/Microsoft Visual Studio/2017/Professional/MSBuild/15.0/bin/msbuild.exe)

So perhaps you are using a version that's really old?

I also noticed you are using ToolsVersion="3.5", you should also bump that up too. That's ancient.

C.J.
  • 15,637
  • 9
  • 61
  • 77