This article will show you some features of the Windows Installer XML, such as: 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 PREREQUISITESWhy 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 projectAdd Bootstrapper Project to SolutionTo add a new Bootstrapper project to Visual Studio 2012:Figure 1: Add Bootstrapper ProjectCreate Package GroupHere we have two options that :
Install Prerequisites from our setup fileNote: 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.Figure 2: Copy and Paste the FileNow 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.Figure 3: ExePackage ElementSourceFile: 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.Figure 4 Add WixUtilExtension.dllAdd that file to the <WIX> element:Figure 5: Add UtilExtension to Wix elementNow search the Registry values:Figure 6: Search RegistryAdd the package to the chain.Now we have added that package to the Chain.Figure 7: Add Package to ChainWe 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.Figure 8: add DownloadUrl PropertyIt 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.Figure 9: Add setup project to the Bootstrapper projectAdd WixDemoWPFAppVS2012.Setup.msi file to the Bootstrapper project:Figure 10: Add WixDemoWPFAppvs2012.setup..msi file to projectNow just build your Bootstrapper project and open the bin folder and run the setup.Creating DatabaseNote: 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.Figure 11: Product.wxs fileTo create a database in SQL we can use this procedure:
Add a reference of the two files in our solution:Figure 12: Add SQL and Util Extension DLL FilesAdd that DLL file to the Product.wxs file:Figure 13: Add the DLL files to the Product.wxs FileCreate a database user and add a *.sql file:Figure 14: Create Database UserWe need to provide the CreateTable.sql file in the solution. To do that just copy that file and paste it to the solution.Figure 15: Add CreateTable.sqlAdd a new component for the database:Figure 16: Add New Database componentAdd that component to the features.Figure 17: Add Component to the FeatureNow just build you project and run the setup file; it will create a database with a table.Creating Uninstall ShortcutThis shortcut is used to uninstall the application and its data it will be created in the Program Menu Folder.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.
C# Corner. All contents are copyright of their authors.