![](http://habrastorage.org/getpro/habr/avatars/d43/199/9c6/d431999c6a0513346e2699f8891020f3.jpg)
Creating an installer using WiX. Part 3
This time we will create something more complicated than the installation package from the first article . We will learn to make changes to the installation steps and create our own installer dialogs.
Our new installer will include the following steps:
1. Welcome
2. Choosing the installation method
![](https://habrastorage.org/getpro/habr/post_images/c4d/155/0f8/c4d1550f885d5678d508159588271619.gif)
3. Choosing the components to install
![](https://habrastorage.org/getpro/habr/post_images/801/e1f/799/801e1f79925106e052f601dae760ba78.gif)
4. Creating shortcuts
![](https://habrastorage.org/getpro/habr/post_images/ba2/211/057/ba221105720b948e7deec6d43b91daa4.gif)
5. Everything is ready for installation
6. Installation process
7. Final dialogue
Two programs will be installed: Notepad and Calculator .
The installer will offer three types of installation: Normal , Custom , Full. Let us set the condition: if the user chose the usual installation, the Calculator should not be installed, with a full one, notepad and a calculator should be installed, with a selective one, what the user selected.
Let's start by creating a new project and immediately adding Russian language support and a link to WixUIExtension .
In a previous article, I pointed out the need to include the WixUI_ru-ru.wxl file in the project , in fact, there is no such need, because a file with Russian localization is already included in the current version of WiX. I didn’t look, I repent.
As a set of dialog boxes this time we will use the WixUI_Mondo set . Add a link to this set at the end of the Product.wxs file In chapter.
Next, we will divide our project into several files. Take out the descriptioninto a separate Features.wxs file . Just create a separate file for description of installed files Files.wxs , create shortcuts Shortcuts.wxs and take out the variables in the file Variables.wxi as described in the second article .
Now add the files to install: notepad and calculator. Notepad will be an obligatory element, the calculator will be optional and will be part of the notepad component as shown in the screenshot Selecting components to install
Add the following code to the Files.wxs file :
We created a description of two different components so that these components can be included in different options () installation. Add installation options, for this, add the code to the Features.wxs file :
As you can see, the FeatureCalc installation option is part of FeatureNotepad, i.e. is dependent and, accordingly, is displayed as a child in the window for selecting components for installation.
In the key parameterswe see parameters such as Title and Description. These parameters are responsible for the name of the component in the tree of components for installation and its description, which appears in the right part of the window when selecting a component. Another interesting point is the ConfigurableDirectory parameter - sets the identifier of the directory, the path of which will change when the Browse button is clicked . In this case, this is the INSTALLLOCATION directory, i.e. the one in which our product will be installed. If you do not specify the ConfigurableDirectory parameter value, the user will not be able to change the installation path.
Add a link to the installation options in the Product.wxs file :
It remains to add shortcuts to the Start menu and you can collect the first version of the package. To add shortcuts to the Shortcuts.wxs file, insert the code:
A description of the shortcuts was added, now you need to add shortcuts to the appropriate installation options:
Let's try to assemble our project and look at what happened. Options are selected, files are installed, but this is not like what we planned at the very beginning. There is a window of the license agreement, which we decided to remove and there is no window for creating shortcuts.
We begin to make changes to the display order of the installation matser windows. To do this, you must either create your own set of dialogue windows, or take the finished one as a basis and make your changes. To reduce the time, download the archive with the WiX sources , unpack it, find the file WiXUI_Mondo.wxs (src \ ext \ UIExtension \ wixlib), rename it to WiXUI_Wizard.wxs . Next, open this file, find the line:
Made so that during assembly we do not get the error " Duplicate symbol 'WixUI: WixUI_Mondo' found. " an element with the identifier WixUI_Mondo already exists in the WixUIExtension library a link to which we added to our project.
We include this file in our project. Change the link:
We remove the license agreement from the package, for this we delete the lines from the WixUI_Wizard.wxs file :
These lines determined the actions when clicking Next and Previous buttons in the license agreement dialog.
Change the line:
This line set the action when you click Next in the welcome window. We changed the action and assigned the display of the installation type selection window (SetupTypeDlg) when clicking Next.
Line:
This line set the action when clicking the Back button in the installation type selection window. We changed the action and assigned a return to the welcome window when you click the Back button.
All we did was delete the mention of the window with the license agreement and “jumped” through it, overriding the reaction of the Back and Next buttons. The lines that determine the reaction of the Back And Next buttons in the license agreement window could not be removed by overriding the actions of the Next and Back buttons in the welcome dialogs and choosing the installation method, we already excluded the dialog with the license from the installation process.
If we assemble and run the installation package now, we will see the same as before, but without the license agreement window.
Create your own shortcut dialog. Add a new file to the projectWixUI_Shortcuts.wxs in which we define the appearance of the new dialog box:
There are two ways to create dialogs: create them yourself by editing the code, or you can use a visual editor, for example, Sharp Develop. I did just that, taking the SetupTypeDlg.wxs dialog (src \ ext \ UIExtension \ wixlib) as a basis, removed the excess, added the missing.
We will include our new dialogue in the installation process. The new dialog should be displayed after the dialog for selecting components for installation, or after the dialog for selecting the type of installation if the Normal or Full buttons are clicked. Open the WixUI_Wizard.wxs file and add the following:
Now you need to redefine the response to button clicks in the dialogs SetupTypeDlg , CustomizeDlg , VerifyReadyDlg . All together will look like this (I do not give unchanged lines):
We collect, launch, see a new window. One problem is whether checkboxes are standing or not - a shortcut on the desktop is not created, in the Start menu it is created anyway. Those. no reaction. And all because we have not tied anything to these checkboxes. First, add two new properties to the Product.wxs file :
Our checkboxes have the same properties: Property = “SHORTCUT_DESKTOP” and Property = “SHORTCUT_PROGRAMMENU”, hence the connection. If we change the state of the checkboxes in the dialog box, the value of Property will also change. Now we need to link the creation of shortcuts and property values. This is done very simply. The condition is added to the component:
If the expression is inside the keytrue, then the component will be installed.
All together looks like this:
Do not forget to addand for the ShortcutCalc component.
All that remains to be done is to add desktop shortcuts. Add a new directory to the Products.wxs file
Description of shortcuts in the Shortcuts.wxs file :
Add shortcut links to the Features.wxs file :
Almost done. It remains to fulfill one more condition, with a normal installation, only a notebook should be installed. To fulfill this condition, add in responsible for installing the calculator.
Level parameter when using inside is a must. He sets the Level itself if the condition is met. In this case, it is INSTALLLEVEL = 3, the value 3 is set to the INSTALLLEVEL property if the user selected Normal installation. How did I find out? I looked at the sources of the dialog for choosing the type of installation SetupTypeDlg.wxs (by the way, there are a lot of interesting things there, by the way)
The value 0 of the Level parameter means that the installation option will be disabled.
We assemble, launch, install.
Project sources can be downloaded here
. That's all. Next time I’ll talk about CustomActions , a very interesting thing that allows you to add any actions to the installation package.
Our new installer will include the following steps:
1. Welcome
2. Choosing the installation method
![](https://habrastorage.org/getpro/habr/post_images/c4d/155/0f8/c4d1550f885d5678d508159588271619.gif)
3. Choosing the components to install
![](https://habrastorage.org/getpro/habr/post_images/801/e1f/799/801e1f79925106e052f601dae760ba78.gif)
4. Creating shortcuts
![](https://habrastorage.org/getpro/habr/post_images/ba2/211/057/ba221105720b948e7deec6d43b91daa4.gif)
5. Everything is ready for installation
6. Installation process
7. Final dialogue
Two programs will be installed: Notepad and Calculator .
The installer will offer three types of installation: Normal , Custom , Full. Let us set the condition: if the user chose the usual installation, the Calculator should not be installed, with a full one, notepad and a calculator should be installed, with a selective one, what the user selected.
Let's start by creating a new project and immediately adding Russian language support and a link to WixUIExtension .
In a previous article, I pointed out the need to include the WixUI_ru-ru.wxl file in the project , in fact, there is no such need, because a file with Russian localization is already included in the current version of WiX. I didn’t look, I repent.
As a set of dialog boxes this time we will use the WixUI_Mondo set . Add a link to this set at the end of the Product.wxs file In chapter
Next, we will divide our project into several files. Take out the description
Now add the files to install: notepad and calculator. Notepad will be an obligatory element, the calculator will be optional and will be part of the notepad component as shown in the screenshot Selecting components to install
Add the following code to the Files.wxs file :
* This source code was highlighted with Source Code Highlighter.
We created a description of two different components so that these components can be included in different options (
* This source code was highlighted with Source Code Highlighter.
As you can see, the FeatureCalc installation option is part of FeatureNotepad, i.e. is dependent and, accordingly, is displayed as a child in the window for selecting components for installation.
In the key parameters
Add a link to the installation options in the Product.wxs file :
It remains to add shortcuts to the Start menu and you can collect the first version of the package. To add shortcuts to the Shortcuts.wxs file, insert the code:
Name="Блокнот"
Description="$(var.ProductName)"
Target="[INSTALLLOCATION]Notepad.exe"
WorkingDirectory="INSTALLLOCATION"/>
Key="Software\$(var.Manufacturer)\$(var.ProductName)"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes"/>
Name="Калькулятор"
Description="$(var.ProductName)"
Target="[INSTALLLOCATION]Calc.exe"
WorkingDirectory="INSTALLLOCATION"/>
Key="Software\$(var.Manufacturer)\$(var.ProductName)"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes"/>
* This source code was highlighted with Source Code Highlighter.
A description of the shortcuts was added, now you need to add shortcuts to the appropriate installation options:
* This source code was highlighted with Source Code Highlighter.
Let's try to assemble our project and look at what happened. Options are selected, files are installed, but this is not like what we planned at the very beginning. There is a window of the license agreement, which we decided to remove and there is no window for creating shortcuts.
We begin to make changes to the display order of the installation matser windows. To do this, you must either create your own set of dialogue windows, or take the finished one as a basis and make your changes. To reduce the time, download the archive with the WiX sources , unpack it, find the file WiXUI_Mondo.wxs (src \ ext \ UIExtension \ wixlib), rename it to WiXUI_Wizard.wxs . Next, open this file, find the line:
and change toMade so that during assembly we do not get the error " Duplicate symbol 'WixUI: WixUI_Mondo' found. " an element with the identifier WixUI_Mondo already exists in the WixUIExtension library a link to which we added to our project.
We include this file in our project. Change the link:
on the
We remove the license agreement from the package, for this we delete the lines from the WixUI_Wizard.wxs file :
1 LicenseAccepted = "1"
These lines determined the actions when clicking Next and Previous buttons in the license agreement dialog.
Change the line:
on the
1
1
This line set the action when you click Next in the welcome window. We changed the action and assigned the display of the installation type selection window (SetupTypeDlg) when clicking Next.
Line:
change to
1
1
This line set the action when clicking the Back button in the installation type selection window. We changed the action and assigned a return to the welcome window when you click the Back button.
All we did was delete the mention of the window with the license agreement and “jumped” through it, overriding the reaction of the Back and Next buttons. The lines that determine the reaction of the Back And Next buttons in the license agreement window could not be removed by overriding the actions of the Next and Back buttons in the welcome dialogs and choosing the installation method, we already excluded the dialog with the license from the installation process.
If we assemble and run the installation package now, we will see the same as before, but without the license agreement window.
Create your own shortcut dialog. Add a new file to the projectWixUI_Shortcuts.wxs in which we define the appearance of the new dialog box:
* This source code was highlighted with Source Code Highlighter.
There are two ways to create dialogs: create them yourself by editing the code, or you can use a visual editor, for example, Sharp Develop. I did just that, taking the SetupTypeDlg.wxs dialog (src \ ext \ UIExtension \ wixlib) as a basis, removed the excess, added the missing.
We will include our new dialogue in the installation process. The new dialog should be displayed after the dialog for selecting components for installation, or after the dialog for selecting the type of installation if the Normal or Full buttons are clicked. Open the WixUI_Wizard.wxs file and add the following:
1 1
* This source code was highlighted with Source Code Highlighter.
Now you need to redefine the response to button clicks in the dialogs SetupTypeDlg , CustomizeDlg , VerifyReadyDlg . All together will look like this (I do not give unchanged lines):
1 1 1
WixUI_InstallMode = "InstallCustom"
WixUI_InstallMode = "InstallTypical" OR WixUI_InstallMode = "InstallComplete"1
WixUI_InstallMode = "Change"
WixUI_InstallMode = "Repair" OR WixUI_InstallMode = "Remove"
* This source code was highlighted with Source Code Highlighter.
We collect, launch, see a new window. One problem is whether checkboxes are standing or not - a shortcut on the desktop is not created, in the Start menu it is created anyway. Those. no reaction. And all because we have not tied anything to these checkboxes. First, add two new properties to the Product.wxs file :
1 1
Our checkboxes have the same properties: Property = “SHORTCUT_DESKTOP” and Property = “SHORTCUT_PROGRAMMENU”, hence the connection. If we change the state of the checkboxes in the dialog box, the value of Property will also change. Now we need to link the creation of shortcuts and property values. This is done very simply. The condition is added to the component:
SHORTCUT_PROGRAMMENU
If the expression is inside the key
All together looks like this:
Name="Блокнот"
Description="$(var.ProductName)"
Target="[INSTALLLOCATION]Notepad.exe"
WorkingDirectory="INSTALLLOCATION"/>
SHORTCUT_PROGRAMMENU
* This source code was highlighted with Source Code Highlighter.
Do not forget to add
All that remains to be done is to add desktop shortcuts. Add a new directory to the Products.wxs file
Description of shortcuts in the Shortcuts.wxs file :
SHORTCUT_DESKTOP
SHORTCUT_DESKTOP
* This source code was highlighted with Source Code Highlighter.
Add shortcut links to the Features.wxs file :
* This source code was highlighted with Source Code Highlighter.
Almost done. It remains to fulfill one more condition, with a normal installation, only a notebook should be installed. To fulfill this condition, add
INSTALLLEVEL=3
Level parameter when using
1
The value 0 of the Level parameter means that the installation option will be disabled.
We assemble, launch, install.
Project sources can be downloaded here
. That's all. Next time I’ll talk about CustomActions , a very interesting thing that allows you to add any actions to the installation package.