Msbuild 如何在批处理任务中使用shared ItemGroup元素
我正在尝试使用MSbuild为两种不同的平台自动创建Firefox插件: 我设置了共享文件,这些文件与Mac和Windows相同,并且具有特定于平台的文件 我想批量制作XPI,这只是一个按平台重命名的Zip文件,但我找不到正确的方法来添加平台无关的共享文件作为Zip任务的输入。目前,我的解决方案是使用平台windows和平台mac复制共享文件项,然后按平台参数批处理Zip任务。我觉得我的解决方案不是最优的。也许社区可以提出更好的解决方案。下面是我用注释创建的简化解决方案:Msbuild 如何在批处理任务中使用shared ItemGroup元素,msbuild,msbuild-task,msbuildcommunitytasks,msbuild-4.0,Msbuild,Msbuild Task,Msbuildcommunitytasks,Msbuild 4.0,我正在尝试使用MSbuild为两种不同的平台自动创建Firefox插件: 我设置了共享文件,这些文件与Mac和Windows相同,并且具有特定于平台的文件 我想批量制作XPI,这只是一个按平台重命名的Zip文件,但我找不到正确的方法来添加平台无关的共享文件作为Zip任务的输入。目前,我的解决方案是使用平台windows和平台mac复制共享文件项,然后按平台参数批处理Zip任务。我觉得我的解决方案不是最优的。也许社区可以提出更好的解决方案。下面是我用注释创建的简化解决方案: <?xm
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectMSBuildToolsPath Condition=" '$(ProjectMSBuildToolsPath)' == '' ">MSBuild</ProjectMSBuildToolsPath>
</PropertyGroup>
<!-- Required Import to use MSBuild Community Tasks -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<!-- Default platform type is shared-->
<ItemDefinitionGroup>
<ZipFiles>
<Platform>Shared</Platform>
</ZipFiles>
</ItemDefinitionGroup>
<ItemGroup>
<ZipFiles Include="chrome\overlay.js" />
<ZipFiles Include="chrome\Win\methodContainer.js">
<Platform>Win</Platform>
</ZipFiles>
<ZipFiles Include="chrome\Mac\dataContainer.js">
<Platform>Mac</Platform>
</ZipFiles>
</ItemGroup>
<Target Name="_PrepareItemsForZip" Outputs="$(Platform)">
<ItemGroup>
<!-- Merge Shared and Windows specific files -->
<ZipFilesToWin Include="@(ZipFiles)" Condition="('%(ZipFiles.Platform)' == 'Shared') Or ('%(ZipFiles.Platform)' == 'Win')" >
<Platform>Win</Platform>
</ZipFilesToWin>
<!-- Merge Shared and Mac specific files -->
<ZipFilesToMac Include="@(ZipFiles)" Condition="('%(ZipFiles.Platform)' == 'Shared') Or ('%(ZipFiles.Platform)' == 'Mac')" >
<Platform>Mac</Platform>
</ZipFilesToMac>
</ItemGroup>
<!-- Merge Mac and Windows files set -->
<ItemGroup>
<_ZipFiles Include="@(ZipFilesToWin);@(ZipFilesToMac)" />
</ItemGroup>
</Target>
<!-- batch zipping files based on input platform -->
<Target Name="MakeXPI" DependsOnTargets="_PrepareItemsForZip" Inputs="@(_ZipFiles)" Outputs="%(Platform)" >
<Message Text="Zipped files: @(_ZipFiles) %(Platform)" Importance="high"/>
<Zip Files="@(_ZipFiles)" WorkingDirectory="" ZipFileName="CoolAddon-%(Platform).xpi" ZipLevel="9" />
</Target>
</Project>
将它们解压缩到类似SharedProperties.properties的文件:
然后只需导入所需的目标/脚本:
<Project ... >
<Import Project="SharedProperties.properties" />
您尝试过我提出的解决方案吗?我不知道如何使用您的解决方案?好的,据我所知,您正在跨多个MSBuild脚本复制property Platform,我建议在单独的文件SharedProperties.properties中提取共享属性,然后导入它,抱歉。我对这个问题的解释不清楚。我没有复制平台属性的问题。我想只在Mac和Win平台上做一个批处理任务,这也需要共享。但默认情况下,批处理将考虑共享,所以我将运行任务三次,用于Mac、Win和Shared。所以我的解决方案是在构建之前将共享更改为Mac并赢两次。在这种情况下,批处理将运行两次。很抱歉,但仍不确定是否正确,因此您希望对所有三种平台Mac/Win/Shared一次性运行Zip任务1和2?如果是这样,为什么不简单地对Shared执行与对ZipFilesToWin和ZipFilesToShared相同的操作?
<Project ... >
<Import Project="SharedProperties.properties" />