【问题标题】:In Wix, can one define a ComponentGroup and Directory at the same time?在 Wix 中,可以同时定义 ComponentGroup 和 Directory 吗?
【发布时间】:2011-01-09 07:52:08
【问题描述】:

我是 WiX 的新手。很新。有没有办法同时定义 ComponentGroup 和 Directory?

我有大量文件,总共大约 300 个左右,需要分成多个组,每个组大约有 50 个文件。

使用 heat.exe,我能够创建一个片段,为每个文件创建组件。我想避免在单独的 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,因此我不确定是否应该标记解决方案。如果有人觉得下面的答案之一是我现在相当老的问题的答案,请告诉我,我会这样标记适当的答案。

【问题讨论】:

    标签: wix


    【解决方案1】:

    直接回答这个问题:是的,你可以。

    <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>
    

    但是,最好让热量为您完成这项工作。

    【讨论】:

      【解决方案2】:
      $ heat dir your_dir -gg -sfrag -cg ComponentGroupName -o myout.wxs
      

      使用 -h 标志或选项说明。

      这将为您提供一个 ComponentGroup ID,您可以将其插入您想要的功能中。

      【讨论】:

        【解决方案3】:

        我希望我能正确理解您的问题。我在每次构建时都使用 heat 工具来自动生成包含针对我的构建输出目录内容的组件的 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 文件中定义了一个“收获任务”(它不是绝对干净,但它可以工作)。 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="&quot;$(WixExtDir)heat&quot; 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”来定义componentGroup。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-09-20
          • 2020-04-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多