Josh
Josh

Reputation: 309

WIX: Create a fragment for features

I am creating a Windows Installer MSI using WIX. I want to separate files into different fragments, to have small chunks of code in each wxs file.

Currently I have below files: - Product.wxs which contains Product, Package, MediaTemplate and Feature elements. - Directories.wxs which contains folders structures and components to give permissions to user and remove folders on uninstall.

I want to take all my features out of Product.wxs too, and create it's own file, called Features.wxs.

Inside Directories.wxs, I have below line of code:

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

With having above code, since I am referencing this Component in a Feature element, I am certain that my Product.wxs and Directories are linked.

But when I create a Feature.wxs file and move below lines of code to it:

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

I don't know how/where to reference this fragment/features in my Product.wxs.

Upvotes: 0

Views: 2308

Answers (2)

Bob
Bob

Reputation: 459

I put my Feature stuff in a different file as well, and the only thing that I need to reference them is the Feature's ID.

Here's a code example. Here's an entire feature file that I have:

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

And here's how I reference it in Product.wxs. I'll show you the entire file from the MajorUpgrade element to its bitter end:

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

That's it. Maybe you're not using FeatureRef?

Upvotes: 0

Christopher Painter
Christopher Painter

Reputation: 55620

Create a FeatureGroup with FeatureRef elements and then in Product.wxs use a FeatureGroupRef to bring into scope.

Upvotes: 1

Related Questions