WiX Tutorials – Add features, components and files to MSI

In a previous post we have seen how to create a basic empty MSI only with the default information in it.

Let’s take it a step further and add a Feature, Component, File and Shortcut to our MSI.

Assuming you have WiX installed and all the files created in the first tutorial, let’s kick it up a notch and add them.

Open up your example1.wxs and paste the following:


<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="12345678-1111-2222-3333-666666666666"

Name="My First Installer" Version="1.0.0.0" Manufacturer="My Company" Language="1033">
<Package InstallerVersion="200" Compressed="yes" Comments="Hello, this is my first installer"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="MyFirstInstaller">
<Component Id="Files" Guid="11111111-2222-3333-4444-555555555555">
<File Id="File1" Source="Trace32.exe"/>
</Component>
</Directory>
</Directory>
</Directory>

<Feature Id="Feature1" Level="1" Title="First feature" Description="This is the one and only feature in this installation">
<ComponentRef Id="Files"/>
</Feature>
</Product>
</Wix>

Compared with the previous example1.wxs it is a little bit bigger right?

Let’s explain what is happening in the XML.

 

First, we must tell WiX to create a cabinet file which will be embedded inside the MSI:


<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>

 

After that we must create a folder structure where we want to place our files:


<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="MyFirstInstaller">
</Directory>
</Directory>
</Directory>

 

With this, we are saying to WiX that we want to create a folder structure in %ProgramFiles%\MyFirstInstaller.

So let’s now create a Component which contains a file. In our case we will use Trace32.exe:


<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="MyFirstInstaller">
<Component Id="Files" Guid="11111111-2222-3333-4444-555555555555">
<File Id="File1" Source="Trace32.exe"/>
</Component>
</Directory>
</Directory>
</Directory>

 

By adding this, the component will have the target to the INSTALLDIR.

Place your file (in our case Trace32.exe) near the example.wsx and make_msi.bat, basically in the same folder.

 

But, as we all know, in order to have a component, we also have to have a Feature where to place this component. So let’s create it:


<Feature Id="Feature1" Level="1" Title="First feature" Description="This is the one and only feature in this installation">
<ComponentRef Id="Files"/>
</Feature>

We are creating a new feature called Feature1 that has the previous created Component named Files.

 

That’s it, now double click the make_installer.bat created in the previous tutorial. The build operation is fast and now we have our updated example1.MSI.

So let’s open it with Advanced Installer and see how we did.

As we can see, we created a feature called First Feature which has our desired component named Files. This has the installation directory in [INSTALLDIR] and contains the file we specified to WiX.

You can also check for the file in Files and Folders

That’s it for the second tutorial!

For more information and documentation about WiX, check out this page.

Sharing is caring!

Leave a comment

Your email address will not be published. Required fields are marked *

6 − two =