MSBuild 对三个独立变量进行批处理
我一直在编写一个基于 MSBuild 的构建系统,到了项目结束时,我需要通过批处理三个变量来运行一个 msbuild 文件 88 次:
Configuration = Debug;贝塔;发布;评价
平台 = x86; x64
语言=中文; CS;德; CN;英语; FR;它;太平绅士;击倒; 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>
I have been writing a build system based on MSBuild, and am to the end of the project where I need to essentially run the one msbuild file 88 times by batching over three variables:
Configuration = Debug; Beta; Release; Evaluation
Platform = x86; x64
Language = CN; CS; DE; EN; ES; FR; IT; JP; KO; PL; TW
I want to build:
"Debug x86 CN", "Debug x86 CS", ... "Debug x86 TW"
"Debug x64 CN", ...
I can, of course, define 88 of these:
<ItemGroup>
<ToBuild Include="Debug_x86_CN">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
<Language>EN</Language>
</ToBuild>
<ItemGroup>
And then batch based on metadata. But what a drag! Can I create the 88 permutations in code, so adding a language is as easy as adding three characters to an 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 Anders Ljusberg< /a> 几年前发布了对此的答案。解决方案是使用 CreateItem 任务将各个 ItemGroup 合并为一个 ItemGroup。每个项目的叉积一次需要在一个新的 ItemGroup 中进行(在本例中为 _Config_X_Language 和 _Config_X_Language_X_Platform),以防止空元数据泄漏(如果您尝试重用 _Config_X_Language,您将获得具有空 Platform 的项目, n 除了 $(Platform) 中的平台。
Thanks to Anders Ljusberg for posting an answer to this years ago. The solution is to use the CreateItem task to combine the individual ItemGroups into one ItemGroup. The cross product of each item needs to be done one at a time into a new ItemGroup (in this case _Config_X_Language and _Config_X_Language_X_Platform) to prevent empty metadata from leaking in (if you try to reuse _Config_X_Language, you'll get items with empty Platform, n addition to the platforms in $(Platform).
将各个 ItemGroup 合并为一个 ItemGroup 是一个好主意。
但是,使用此方法时,MSBuild 构建项目时会忽略属性 BuildInParallel(所有项目构建一致)。
所以你需要一些东西来补充脚本:
It is a good idea to combine the individual ItemGroups into one ItemGroup.
However, when using this method MSBuild builds projects ignoring attribute BuildInParallel (all projects building consistently).
So you need something to supplement script: