我一直在编写基于MSBuild的构建系统,并且到项目的结尾,我需要通过批处理三个变量来本质上运行一个msbuild文件88次:
配置=调试; Beta;释放;评价
平台= x86; x64
语言= CN; CS; DE; EN; ES; FR;它; J.P; KO; PL; TW
我要建立:
“调试x86 CN”,“调试x86 CS”,...“调试x86 TW”
“调试x64 CN”,...
我当然可以定义其中的88个:
<ItemGroup>
<ToBuild Include="Debug_x86_CN">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
<Language>EN</Language>
</ToBuild>
<ItemGroup>
然后基于元数据进行批处理。但是,真是太累了!我可以在代码中创建88个排列,因此添加语言就像向ItemGroup添加三个字符一样容易:
<ItemGroup>
<AllConfigurations Include="Beta; Release; Evaluation;"/>
<AllPlatforms Include="x86; x64" />
<AllLanguages Include="CN; CS; DE; EN; ES; FR; IT; JP; KO; PL; TW" />
</ItemGroup>
最佳答案
感谢Anders Ljusberg在几年前发布了答案。解决方案是使用CreateItem任务将单个ItemGroups组合为一个ItemGroup。每个项目的叉积需要一次放入一个新的ItemGroup中(在本例中为_Config_X_Language和_Config_X_Language_X_Platform),以防止空元数据泄漏(如果您尝试重用_Config_X_Language,则将获得具有空Platform的项目, n除了$(Platform)中的平台。
<ItemGroup>
<Configuration Include="Beta; Release; Evaluation;"/>
<Platform Include="x86; x64" />
<Language Include="CN; CS; DE; EN; ES; FR; IT; JP; KO; PL; TW" />
</ItemGroup>
<!-- Create an ItemGroup that is the cross product of Configuration and Language: -->
<CreateItem Include="@(Configuration)" AdditionalMetadata="Language=%(Language.Identity);" >
<Output ItemName="_Config_X_Language" TaskParameter="Include"/>
</CreateItem>
<!-- Create another ItemGroup that is the cross product of _Configuration_X_Language and Platform: -->
<CreateItem Include="@(_Config_X_Language)" AdditionalMetadata="Platform=%(Platform.Identity);" >
<Output ItemName="_Config_X_Language_X_Platform" TaskParameter="Include"/>
</CreateItem>
<!-- Task batch over each unique set of metadata on AllBuilds -->
<MSBuild Projects="myproject.msbuild"
Properties="Configuration=%(_Config_X_Language_X_Platform.Identity);
Platform=%(_Config_X_Language_X_Platform.Platform);
Language=%(_Config_X_Language_X_Platform.Language);"
Targets="MyTarget"
BuildInParallel="true" />