我正在尝试使用 MSbuild 为两个不同平台自动创建 Firefox 插件:我有共享文件集,这些文件集对于 Mac 和 Windows 是相同的,并且具有特定于平台的文件。
我想按平台批量制作 XPI(这只是一个重命名的 Zip 文件)的任务,但我找不到添加平台不可知(共享)文件作为 Zip 任务输入的正确方法。目前,我的解决方案是使用平台 windows 和平台 mac 复制共享文件项,然后通过平台参数批处理 Zip 任务。我有一种感觉,我的解决方案不是最优的。也许社区可以提出更好的解决方案。以下是我创建的带有注释的简化解决方案:
<?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>