WIX:为功能创建片段

WIX: Create a fragment for features

我正在使用 WIX 创建 Windows 安装程序 MSI。我想将文件分成不同的片段,以便在每个 wxs 文件中包含小块代码。

目前我有以下文件: - Product.wxs 其中包含 Product、Package、MediaTemplate 和 Feature 元素。 - Directories.wxs 其中包含文件夹结构和组件,用于向用户授予权限并在卸载时删除文件夹。

我也想从 Product.wxs 中取出我的所有功能,并创建它自己的文件,名为 Features.wxs.

Directories.wxs 中,我有以下代码行:

<Component Id="Component1" Guid="PUT_GUID_HERE" Directory="Subfolder">
  <CreateFolder>
    <util:PermissionEx GenericAll="yes" ChangePermission="yes" Delete="yes" DeleteChild="yes" User="Users"/>
  </CreateFolder>
</Component>

有了上面的代码,因为我在 Feature 元素中引用了这个组件,所以我确定我的 Product.wxsDirectories 已链接。

但是当我创建一个 Feature.wxs 文件并将下面的代码行移动到它时:

<Feature Id="CreateDirectoriesFeature" Title="Feature1" Level="1">
  <ComponentRef Id="Component1"/>
</Feature>

我不知道 how/where 在我的 Product.wxs.

中引用这个 fragment/features

使用 FeatureRef 元素创建一个 FeatureGroup,然后在 Product.wxs 使用 FeatureGroupRef 将其引入范围。

我也将我的功能资料放在不同的文件中,我唯一需要引用它们的是功能的 ID。

这是一个代码示例。这是我拥有的 完整 功能文件:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
      <Feature Id="Feature_Name"
               Level="1">
          <ComponentRef Id="Component_Name"/>
      </Feature>
    </Fragment>
</Wix>

下面是我在 Product.wxs 中引用它的方式。我将向您展示从 MajorUpgrade 元素到最后的整个文件:

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes"/>
        <FeatureRef Id="Feature_Name"/>
    </Product>
</Wix>

就是这样。也许您没有使用 FeatureRef?