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>