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