Installing Prerequisites Using WIX Bootstrapper Project and Other Features of WIX

This article will show you some features of the Windows Installer XML, such as:

Windows-Installer-XML.jpg
 
NOTE: If you are new to Windows Installer XML than please refer to my article Getting Started with WIX; here is the link: http://www.c-sharpcorner.com/UploadFile/cb88b2/getting-started-with-wix-windows-installer-xml-in-vs2012/.

USING A WIX BOOTSTRAPPER PROJECT TO INSTALL PREREQUISITES

Why use a WIX Bootstrapper project?

In our project there are so many things that we need to install before our software will be installed. At that time we can use this to bundle the prerequisites (like .Net Framework, SQL etc.) of Software or Website. Using this we can put all the necessary things into a single package so it is easy to manage.

How to add a prerequisites to the project

Windows-Installer-XML1.jpg

Add Bootstrapper Project to Solution

To add a new Bootstrapper project to Visual Studio 2012:

Windows-Installer-XML2.jpg

Add-Bootstrapper-Project.jpg

Figure 1: Add Bootstrapper Project

Create Package Group

Here we have two options that :

  • We can install prerequisites from our setup file
    We can download from internet than install file

Install Prerequisites from our setup file

Note: In the "WixDemoWPFAppVS2012.rar" file I have not added "dotNetFx40_Full_x86_x64.exe". Since it is greater than 10 MB in size and I cannot upload the file. Please download it and add that into you project as I have explained in the article.
In this example we will install the .Net Framework 4.0 Full as a prerequisite. You can download that from the link: http://www.microsoft.com/en-in/download/details.aspx?id=17718.

After downloading we need to add that "dotNetFx40_Full_x86_x64.exe" to our Bootstrapper project.

Copy the downloaded file, do the right-click on the bootstrapper project and just paste it.

Copy-and-Paste-the-File.jpg

Figure 2: Copy and Paste the File

Now create a <packageGroup> in the <Fragment> and now in the package Group we have an <Exepackage> element. To understand all the properties please refer to this link: http://wix.sourceforge.net/manual-wix3/wix_xsd_exepackage.htm.

ExePackage-Element.jpg

Figure 3: ExePackage Element

SourceFile: Location of the package to add to the bundle. The default value is the Name attribute, if provided. At a minimum, the SourceFile or Name attribute must be specified.

Compressed: Whether the package payload should be embedded in a container or left as an external payload.

This will add our .Net Framework 4.0 exe to the setup file.

Search Registry

Before installing .Net Framework 4.0 we will determine whether it is already installed; if it is not then we will install it.

To do that we need to search the Registry Values and to do that we need to do add a reference of WixUtilExtention.dll to our project.

Add-WixUtilExtension.dll.jpg

Figure 4 Add WixUtilExtension.dll

Add that file to the <WIX> element:

Add-UtilExtension-to-Wix-element.jpg

Figure 5: Add UtilExtension to Wix element

Now search the Registry values:

Search-Registry.jpg

Figure 6: Search Registry

Add the package to the chain.

Now we have added that package to the Chain.

Add-Package-to-Chain.jpg

Figure 7: Add Package to Chain

We can download from the internet then install the file.

Note: Though we are downloading the file from the internet while setup is running but at the time of the build the project we need to add that file to the solution.

To download it from the internet we need to add a property DownloadURL and Compressed.

Add-DownloadUrl-Property.jpg

Figure 8: add DownloadUrl Property

It will not add a source file to the setup file but when installation is running and it will not find .Net Framework 4.0 in the system then it will download it from the given link.

In both ways you can specify ExePackage, then all the steps are same. We can use this for installing any .exe file.

Note: Add your *.msi file to the Bootstrapper project and add the reference of the setup project to the Bootstrapper project.

Add a reference of the setup project to the Bootstrapper project.

Add-setup-project-to-the-Bootstrapper-project.jpg

Figure 9: Add setup project to the Bootstrapper project

Add WixDemoWPFAppVS2012.Setup.msi file to the Bootstrapper project:

Add-WixDemoWPFAppvs2012-setup..msi file-to-project.jpg

Figure 10: Add WixDemoWPFAppvs2012.setup..msi file to project

Now just build your Bootstrapper project and open the bin folder and run the setup.

Creating Database

Note: We will add these things to our product.wxs (see the Figure 11). I have explained about that file in my previous article. The database will not be added to the Bootstrapper (bundle.wxs) project.

You can get Product.wxs from the link: http://www.c-sharpcorner.com/UploadFile/cb88b2/getting-started-with-wix-windows-installer-xml-in-vs2012/.

Or you can get that file in the .rar file of this article.

Product.wxs-file.jpg

Figure 11: Product.wxs file

To create a database in SQL we can use this procedure:

  1. Add the reference of the two files in our solution:

    • WixUtilExtension.dll
    • WixSqlExtension.dll
       
  2. Create a database user
  3. Add the *.sql file to create the database

Add a reference of the two files in our solution:

Add-Sql-and-Util-Extension.dll-Files.jpg

Figure 12: Add SQL and Util Extension DLL Files

Add that DLL file to the Product.wxs file:

Add.dll-files-to-Product.wxs-File.jpg

Figure 13: Add the DLL files to the Product.wxs File

Create a database user and add a *.sql file:

Create-Db-User.jpg

Figure 14: Create Database User

We need to provide the CreateTable.sql file in the solution. To do that just copy that file and paste it to the solution.

Add-CreateTable.sql.jpg

Figure 15: Add CreateTable.sql

Add a new component for the database:

Add-New-Database-component.jpg

Figure 16: Add New Database component

Add that component to the features.

Add-Component-to-the-Feature.jpg

Figure 17: Add Component to the Feature

Now just build you project and run the setup file; it will create a database with a table.

Creating Uninstall Shortcut

This shortcut is used to uninstall the application and its data it will be created in the Program Menu Folder.

Add-Component-to-the-Feature1.jpg

Conclusion: we can use WIX to install perquisites and create databases; we can do that very easily using WIX.

If this article helps you than please let me know by your comments.


Similar Articles