Creating an installer that includes a Visual Studio bootstrapper package and an MSI built with WiX 3.0
A few days ago, I wrote a blog post describing how to create an MSI-based installer for a Windows game created with XNA Game Studio 3.0. In that post, I described how to create custom actions in the MSI to check for system-level prerequisites (the .NET Framework and the XNA Framework Redistributable) and block the MSI from installing if they are not installed on the user's system.
Adding a bootstrapper to your game installer
The next thing I want to demonstrate is how to expand on the steps in that blog post to create an installer that will do all of the following:
- Check for the presence of prerequisite components for the game on a user's system.
- Download and install any prerequisites that are missing.
- After prerequisites are installed, trigger the installation of the game MSI.
Visual Studio includes a bootstrapper that can do all of the above, and XNA Game Studio 3.0 includes a prerequisite package for the XNA Framework Redistributable 3.0 that integrates with the Visual Studio bootstrapper. As a result, you can use the Visual Studio 2008 or Visual C# 2008 Express Edition IDE to create an installer for your game for both ClickOnce packages and VS setup/deployment projects, and I have previously posted steps for doing this in this blog post.
If you want to create an installer that uses the Visual Studio bootstrapper along with an MSI built with WiX instead of an MSI build with a VS setup/deployment project, you need to perform a couple of additional steps:
- Create an MSBuild project that contains information about the prerequisites you want to include for your game and also contains a GenerateBootstrapper task with the settings that you want to use for your installer.
- Build your MSI with WiX using the steps from my previous blog post.
- Build the bootstrapper for your game by running MSBuild for the project you create in step 1.
Updated sample that builds an MSI and a bootstrapper
I have posted a sample at http://cid-27e6a35d1a492af7.skydrive.live.com/self.aspx/Blog%7C_Tools/WiX%20Samples/wix%7C_sample%7C_xgs30%7C_game%7C_with%7C_bootstrapper.zip that extends my previous sample so you can use it to create a bootstrapper in addition to an MSI. It includes the following additions/changes from the previous sample:
- The file wix_sample_xgs30_game_bootstrapper_netfx35.proj is an MSBuild project file that will create a bootstrapper for a game that will install the .NET Framework 3.5 and the XNA Framework Redistributable 3.0 as prerequisites.
- The file wix_sample_xgs30_game_bootstrapper_netfx20.proj is an MSBuild project file that will create a bootstrapper for a game that will install the .NET Framework 2.0 and the XNA Framework Redistributable 3.0 as prerequisites.
- The file build_wix_sample_xgs30_game.bat has been updated to compile the MSI using WiX v3.0 and then run MSBuild for wix_sample_xgs30_game_bootstrapper_netfx35.proj to create a VS bootstrapper setup.exe package.
How to use the updated sample
To try out this updated sample, you can use the following steps:
- Install Visual Studio 2008 or Visual C# 2008 Express Edition and XNA Game Studio 3.0.
- Install the latest build of WiX v3.0 from http://wix.sourceforge.net/releases/.
- Open Visual Studio and create a project using the Platformer Starter Kit (3.0) project template that is included as a part of XNA Game Studio 3.0.
- Build the x86 release version of the project.
- Download the sample from http://cid-27e6a35d1a492af7.skydrive.live.com/self.aspx/Blog%7C_Tools/WiX%20Samples/wix%7C_sample%7C_xgs30%7C_game%7C_with%7C_bootstrapper.zip.
- Create a sub-folder named Setup in the Platformer game project that you created above.
- Extract the contents of wix_sample_xgs30_game_with_bootstrapper.zip to the Setup folder. You should end up with a folder structure like c:\Users\myusername\Documents\Visual Studio 2008\Projects\Platformer1\Platformer1\Setup with the contents of the .zip file in there.
- Run the script named build_wix_sample_xgs30_game.bat from the Setup folder to invoke the WiX toolset and build an MSI for the game and then invoke MSBuild to build the bootstrapper setup.exe.
After doing the above, you can copy setup.exe and wix_sample_xgs30_game.msi from the Setup sub-directory to a server and run setup.exe to install your game and its prerequisites on another computer.
Advanced scenario - building an MSI with WiX by using a .wixproj file
Note - it is also possible to create an MSBuild project file to build an MSI using WiX instead of using a batch file that calls the WiX tools directly. I have included a sample MSBuild project file named wix_sample_xgs30_game.wixproj in the new sample that I have posted. It was created by using the Votive Visual Studio package that is a part of the WiX toolset, and it can be built by invoking msbuild.exe directly or by opening the .wixproj file in Visual Studio 2005 or 2008 standard edition or higher on a system that also has WiX v3.0 installed. Keep in mind that Votive is a Visual Studio add-in package, so it can only be installed for use in Visual Studio standard edition or higher. You cannot use it if you only have Visual C# 2008 Express Edition. You can create and build .wixproj files by hand outside of Visual Studio if you only have an Express Edition installed though.
<update date="3/21/2009"> Fixed broken link to sample installer files. </update>