MSBuild 批处理没有按我预期的方式工作。这是一个演示“问题”行为的 MSBuild 脚本的快速示例:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<ItemGroup>
<Platform Condition="('$(Platform)' == 'All') Or ('$(Platform)' == 'x86')" Include="x86" />
<Platform Condition="('$(Platform)' == 'All') Or ('$(Platform)' == 'x64')" Include="x64" />
</ItemGroup>
<Target Name="Build">
<ItemGroup>
<OutputFiles Include="%(Platform.Identity)\*.txt"/>
</ItemGroup>
<Message Importance="high" Text="%(Platform.Identity): @(OutputFiles)" />
</Target>
</Project>
我将此脚本命名为“test.proj”并将其与其他几个子文件夹/文件一起放在一个文件夹中:
.\x86\test-x86.txt
.\x64\test-x64.txt
如果我像这样执行 msbuild msbuild .\test.proj /p:Platform=All
,输出如下所示:
...
Build:
x86: x86\test-x86.txt;x64\test-x64.txt
x64: x86\test-x86.txt;x64\test-x64.txt
...
我期待/希望输出看起来像这样:
...
Build:
x86: x86\test-x86.txt
x64: x64\test-x64.txt
...
换句话说,我希望OutputFiles
根据Message
任务的批处理方式对项目组中的项目进行分组/过滤。
如何更改脚本以获得我想要的行为?我更喜欢不涉及在目标/任务区域中硬编码“平台”值的解决方案。