【发布时间】:2019-06-26 11:09:24
【问题描述】:
我正在更新构建目标,以便在构建期间在两个单独的位置查找要运行的 .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>
【问题讨论】:
标签: msbuild msbuild-propertygroup