我是WiX的新手。 非常新。 有没有办法同时定义一个ComponentGroup和一个Directory?
我有大量的文件,大约有300个,需要分成若干个组,每个组大约有50个文件。
使用 heat.exe,我可以创建一个 Fragment,为每个文件创建 Components。 我希望避免在一个单独的ComponentGroup定义中重新列出每一个组件。 我希望能够将热生成的组件列表包在ComponentGroup定义中,然后简单地在DirectoryRef结构中使用该ComponentGroupRef。
我希望这能让你明白。 我目前必须这样做。
<DirectoryRef Id="FilesDir">
<Component Id="a.txt" Guid="YOUR-GUID">
<File Id="a.txt" KeyPath="yes" Source="SourceDir\a.txt" />
</Component>
<Component Id="b.txt" Guid="YOUR-GUID">
<File Id="b.txt" KeyPath="yes" Source="SourceDir\b.txt" />
</Component>
...
<Component Id="z.txt" Guid="YOUR-GUID">
<File Id="z.txt" KeyPath="yes" Source="SourceDir\z.txt" />
</Component>
</DirectoryRef>
<ComponentGroup Id="FilesGroup">
<ComponentRef Id="a.txt">
<ComponentRef Id="b.txt">
...
<ComponentRef Id="z.txt">
</ComponentGroup>
我必须把每个文件都列出两次 这很臭。
我希望能够做到。
<ComponentGroup Id="FilesGroup">
<Component Id="a.txt" Guid="YOUR-GUID">
<File Id="a.txt" KeyPath="yes" Source="SourceDir\a.txt" />
</Component>
<Component Id="b.txt" Guid="YOUR-GUID">
<File Id="b.txt" KeyPath="yes" Source="SourceDir\b.txt" />
</Component>
...
<Component Id="z.txt" Guid="YOUR-GUID">
<File Id="z.txt" KeyPath="yes" Source="SourceDir\z.txt" />
</Component>
</ComponentGroup>
<DirectoryRef Id="FilesDir">
<ComponentGroupRef Id="FilesGroup">
</DirectoryRef>
这可能吗? 是否有其他方法可以让这个更容易,我只是没有看到?
更新:我们放弃了Wix,因此我不知道是否应该标记一个解决方案。 如果有人觉得下面的答案是我这个老问题的答案,请告诉我,我会把合适的答案标出来。
我希望我对你的问题理解正确。我在每次构建时使用热工具自动生成包含针对构建输出目录内容的组件的wxs。WXS(简化后)是这样的。
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<ComponentGroup Id="CompGroup01">
<Component Id="cmp1D6110E9A0B9E351095F414BEB4D2E35" Directory="Dir01" Guid="*">
<File Id="fil53541B947C7CE0A96A604898F1B825C5" KeyPath="yes" Source="$(var.HarvestDir)\somefile.exe" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
在Product.wxs中,我有一个指向自动生成代码的硬编码链接。
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="INSTALLDIR" Name="myInstallDir">
<Directory Id="Dir01" Name="myInstallSubDir" />
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="MyProductComplete" Level="1">
<ComponentGroupRef Id="CompGroup01" />
</Feature>
在wixproj文件中定义了一个" harvest-task"(虽然不是绝对干净,但也能用)。wixproj并不完整,我删除了所有不相关的部分。
<PropertyGroup>
<!-- relative path to directory from which setup will load input files -->
<MyWixSourceDir>C:\bin</MyWixSourceDir>
<!-- relative path to directory where inputs will be temporarily copied during harvesting -->
<MyWixHarvestDir>tempHarvest</MyWixHarvestDir>
<DefineConstants>Debug;HarvestDirApp=$(ProjectDir)$(MyWixHarvestDir)</DefineConstants>
</PropertyGroup>
<ItemGroup>
<!-- defines item group containing files which represent automatically harvested input for our WiX setup -->
<SetupInputFiles Include="$(MyWixSourceDir)\**\*.*" />
</ItemGroup>
<ItemGroup>
<!-- defines item group of autogenerated files -->
<AutoGeneratedFiles Include="*.autogenerated.wxs" />
</ItemGroup>
<Target Name="BeforeBuild">
<!-- 1) prepare harvesting -->
<!-- remove temporary harvesting directory in case previous build did not cleaned up its temp files and folders -->
<RemoveDir Directories="$(ProjectDir)$(MyWixHarvestDir)" />
<!-- delete old autogenerated files first -->
<Delete Files="@(AutoGeneratedFiles)" ContinueOnError="false" />
<!-- 2) harvest application build output -->
<!-- copies input files into temporary directory so that they can be harvested into WXS file -->
<Copy SourceFiles="@(SetupInputFiles)" DestinationFiles="@(SetupInputFiles->'$(ProjectDir)$(MyWixHarvestDir)\%(RecursiveDir)%(Filename)%(Extension)')" ContinueOnError="false" />
<!-- harvest files and produce WXS file defining all file and directory components for the setup -->
<Exec Command=""$(WixExtDir)heat" dir $(ProjectDir)$(MyWixHarvestDir) -dr Dir01 -sreg -srd -ag -cg CompGroup01 -var var.HarvestDirApp -out InstallDirApp.autogenerated.wxs" ContinueOnError="false" WorkingDirectory="." />
</Target>
<Target Name="AfterBuild">
<!-- 4) clean-up: remove temporary harvesting directory -->
<RemoveDir Directories="$(ProjectDir)$(KbcWixHarvestDir)" />
</Target>
最重要的是执行采集的Exec元素。我用"-dr Dir01 "定义组件将引用 "Dir01 "作为父目录,用"-cg ComGroup01 "定义组件组。
$ heat dir your_dir -gg -sfrag -cg ComponentGroupName -o myout.wxs
使用-h标志或描述选项。
这将给你一个单一的"-dr Dir01"。ComponentGroup ID
您可以将其插入您所需的功能。
为了直接回答这个问题。是的,你可以。
<ComponentGroup Id="FilesGroup" Directory="FilesDir">
<Component Id="a.txt" Guid="YOUR-GUID">
<File Id="a.txt" KeyPath="yes" Source="SourceDir\a.txt" />
</Component>
<Component Id="b.txt" Guid="YOUR-GUID">
<File Id="b.txt" KeyPath="yes" Source="SourceDir\b.txt" />
</Component>
...
<Component Id="z.txt" Guid="YOUR-GUID">
<File Id="z.txt" KeyPath="yes" Source="SourceDir\z.txt" />
</Component>
</ComponentGroup>
<!-- Later in a feature element -->
<Feature ...>
<Feature Id='MainProgram' Title='Program' ...>
<ComponentGroupRef Id='FilesGroup' />
</Feature>
</Feature>
但是,最好是让热为你做这个苦差事。