Create a Windows Installer "MSI" using WiX part2
At first
Last time, we prepared the necessary files and set up the project. This time, edit "Product.wxs" and make various settings of the installer.
Edit installation settings (Product.wxs)
The contents of the Product.wxs file are described in XML format. There are a number of parameters, but first we will make the minimum settings to make sure that the installer can be created. If you want to set it up in more detail, please refer to another article or the official website.
At the time of project creation, the code looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SetupLittleSaviorTrial_x86" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupLittleSaviorTrial_x86" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupLittleSaviorTrial_x86" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
</ComponentGroup>
</Fragment>
</Wix>
Here are some things you need to change: Add tags and attributes that don't exist.
Wix/Product/@Id
Set the GUID that identifies the application.
There are many tools to generate GUID, but it's quick to use the tools that come with Visual Studio. Select the menu "Tools" and "Create GUID".
Get a 36-digit code, including a hyphen, and set it to Wix/Product/@Id.
<Wix>
<Product Id="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" />
Wix/Product/@Name
This is the application name displayed in each part of the installer screen. It can also be the name that appears in the Add and Remove Programs list.
<Wix>
<Product Name="リトルセイバー 体験版" />
Wix/Product/@Manufacturer
Enter the name of the manufacturer. It appears as the installer author or the publisher of the program list.
<Wix>
<Product Manufacturer="ソーサリーフォース">
Wix/Product/UIRef/@Id
Enter an ID that identifies what screen to display in the installation wizard. This time, since it is the minimum configuration to display and install only the license, "WixUI_Minimal" is specified.
<Wix>
<Product>
<UIRef Id="WixUI_Minimal" />
I think that the following site will be helpful in what kind of designation can be done.
Wix/Product/WixVariable/*
Specifies the file to use in the wizard UI. The minimum configuration uses three files: The value of id is fixed and the Value is the file name.
<Wix>
<Product>
<WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
<WixVariable Id="WixUIDialogBmp" Value="dialog.bmp" />
<WixVariable Id="WixUIBannerBmp" Value="banner.bmp" />
Installation application icon
It is used for application icons that appear in "Add and Remove Programs", etc.
In the "SourceFile" of the Icon element, specify the ico file as a relative path from the project folder.
"Property Id="ARPPRODUCTICON" is the association definition of the icon.
<Wix>
<Product>
<Icon Id="LITTLESAVIOR.ICO" SourceFile="LittleSaviorTrial\LittleSavior.ico" />
<Property Id="ARPPRODUCTICON" Value="LITTLESAVIOR.ICO" />
Wix/Fragment (file folder configuration)
Sets the folder configuration to install. Originally, you will also place files, but create only folders first.
The value of "Name" set to "Id="ProgramMenuDir" is the name of the folder placed in the start menu shortcut. Set guids as well.
<Wix>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupLittleSaviorTrial_x86" />
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuDir" Name="リトルセイバー 体験版">
<Component Id="ProgramMenuDir" Guid="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
<RemoveFolder Id="ProgramMenuDir" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
</Component>
</Directory>
</Directory>
</Directory>
</Fragment>
Add installation files
You can also add it to a Product.wxs file by hand. Since a GUID is required for a file, it is difficult to work with more files. So, to add files, use WixEdit to add them.
Launch WixEdit.
Open the Product.wxs file.
Select Files from the icon on the left. Delete the folders below ProgramFilesFolder.
Right-click on the ProgramFilesFolder folder and select Import Folder.
Select the folder where you want to install the files.
A set of files is added to the tree.
In order to associate with other parameters, select the added folder and set "Id" back to "INSTALLFOLDER".
Create a shortcut for the Start menu. select "New" and "Shortcut" from the right-click menu of the exe file.
When Shortcut is added, select it and right-click the blank to add the property.
Add the following parameters: (Change the unique name to match the program.)
Attribute | value |
---|---|
Id | LITTLESAVIORTRIAL. EXE_shortcut |
Name | Little Saber Trial |
Directory | ProgramMenuDir |
WorkingDirectory | INSTALLDIR |
Icon | LITTLESAVIOR. ICO |
IconIndex | 0 |
Advertise | yes |
Then select the "Feature" tab, right-click on "ProductFeature" and select Select Components to add.
Select all.
Added.
Save.
Product.wxs should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" Name="リトルセイバー 体験版" Language="1033" Version="1.0.0.0" Manufacturer="ソーサリーフォース" UpgradeCode="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<UIRef Id="WixUI_Minimal" />
<WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
<WixVariable Id="WixUIDialogBmp" Value="dialog.bmp" />
<WixVariable Id="WixUIBannerBmp" Value="banner.bmp" />
<Icon Id="LITTLESAVIOR.ICO" SourceFile="LittleSaviorTrial\LittleSavior.ico" />
<Property Id="ARPPRODUCTICON" Value="LITTLESAVIOR.ICO" />
<Feature Id="ProductFeature" Title="SetupLittleSaviorTrial_x86" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="LITTLESAVIOR.ICO" />
<ComponentRef Id="LITTLESAVIORTRIAL.EXE" />
<ComponentRef Id="LITTLESAVIORTRIAL.EXE.CONFIG" />
<ComponentRef Id="ProgramMenuDir" />
</Feature>
<UI />
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="LittleSaviorTrial">
<Component Id="LITTLESAVIOR.ICO" DiskId="1" Guid="0B4DD82C-C6EF-4299-8EAB-4F9BB35FD952">
<File Id="LITTLESAVIOR.ICO" Name="LittleSavior.ico" Source="LittleSaviorTrial\LittleSavior.ico" />
</Component>
<Component Id="LITTLESAVIORTRIAL.EXE" DiskId="1" Guid="8D805936-A25E-4DA6-9A0A-A5BDB2AD768D">
<File Id="LITTLESAVIORTRIAL.EXE" Name="LittleSaviorTrial.exe" Source="LittleSaviorTrial\LittleSaviorTrial.exe" KeyPath="yes">
<Shortcut Id="LITTLESAVIORTRIAL.EXE_shortcut" Name="リトルセイバー 体験版" Directory="ProgramMenuDir" WorkingDirectory="INSTALLDIR" Icon="LITTLESAVIOR.ICO" IconIndex="0" Advertise="yes" />
</File>
</Component>
<Component Id="LITTLESAVIORTRIAL.EXE.CONFIG" DiskId="1" Guid="790C427A-A72C-4444-ACD6-ECF32AA788AD">
<File Id="LITTLESAVIORTRIAL.EXE.CONFIG" Name="LittleSaviorTrial.exe.config" Source="LittleSaviorTrial\LittleSaviorTrial.exe.config" />
</Component>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuDir" Name="リトルセイバー 体験版">
<Component Id="ProgramMenuDir" Guid="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
<RemoveFolder Id="ProgramMenuDir" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
</Component>
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
</ComponentGroup>
</Fragment>
</Wix>
Build and run confirmation
Make the solution configuration "Release" in Visual Studio.
Start building from Build Solution.
When the building is successful, an msi file is generated in the "bin\Release" folder.
If you try to run it, the installer will start.
When the installation is complete, a shortcut will be created in the Start menu.
The file is placed in the Program Files (x86) folder.
The application also appears in "Programs and Functions".
Run the application and make sure it is working properly.
Summary
Here we have described the steps to create an MSI installer using Visual Studio and WiX. I'd like to explain the detailed settings in a separate article.