How To: Install the .NET Framework Using a Bootstrapper
Applications written using the .NET Framework often need to install the framework as part of their installation process. Due to dependencies in the .NET Framework installer there is no way to include the framework directly within your package (as you can with the Visual C++ and DirectX runtimes). Instead you have to rely on a bootstrapper: a wrapper application that first installs the .NET Framework and then runs your application's installer.
WiX does not currently provide a bootstrapper, however you can use the one provided by the ClickOnce deployment features in Visual Studio. This document walks through how to modify a WiX project to generate a ClickOnce bootstrapper for .NET Framework 3.5. Similar steps can be used to generate a bootstrapper for other technologies, such as SQL Server Compact Edition and Visual Studio Tools For Office.
Step 1: Open your .wixproj file for editing
To edit your .wixproj file for editing in Visual Studio:
- Open the project in Visual Studio
- In Solution Explorer right click on your project file and select Unload Project
- In Solution Explorer right click on your project file and select Edit <projectname>
Step 2: Add items for prerequisites
Anywhere in your project file, inside the <Project> element, add the following:
<ItemGroup> <BootstrapperFile Include="Microsoft.Net.Framework.3.5"> <ProductName>.NET Framework 3.5</ProductName> </BootstrapperFile> <BootstrapperFile Include="Microsoft.Windows.Installer.3.1"> <ProductName>Windows Installer 3.1</ProductName> </BootstrapperFile> </ItemGroup>
These items will be used in step 3 to tell the bootstrap creation task the list of packages to include. In this case the packages are .NET Framework 3.5 and Windows Installer 3.1 (which is a required component for .NET Framework installation).
Step 3: Add the bootstrap generation task
In your project file uncomment the <TargetName="AfterBuild"></Target> element at the end of the file and replace it with the following:
<Target Name="AfterBuild"> <GenerateBootstrapper ApplicationFile="$(TargetFileName)" ApplicationName="My Application Name" BootstrapperItems="@(BootstrapperFile)" ComponentsLocation="Relative" CopyComponents="True" OutputPath="$(OutputPath)" Path="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\"/> </Target>
This will instruct MSBuild to generate the bootstrapper after the build of your installer is complete. The ApplicationFile attribute will resolve to the location of your application's installer after the build is complete. The ApplicationName attribute is the application name displayed to the user while the bootstrapper is running. The BootstrapperItems attribute provides the list of pre-requisites to include (from Step 2). The ComponentsLocation attribute is set to Relative to indicate the pre-requisites will be installed from the same location as your application's installer. The CopyComponents attribute is set to true to copy the pre-requisite files into the output directory. The OutputPath attribute resolves to the output location of your installer on disk.
The Path attribute indicates the location on your machine of the pre-requisite packages. The location shown above is appropriate for machines with Visual Studio 2008 installed to the default location. For machines with Visual Studio 2005 the default location is C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages.
Step 4: Build the project
Do the following to re-open the project for building:
- Save the changes
- In Solution Explorer right click on your project file and select Reload Project
- In the resulting confirmation dialog select Yes
Then build your project. After your installer is built the bootstrapper will build and be placed in the output directory.
Installing Other Packages
Other packages can be installed using the same mechanism described above. The only additional steps are to modify the list of bootstrapper files in Step 2. The easiest way to obtain the necessary entries is to use the Bootstrapper Manifest Generator tool to create a new MSBuild file with the required packages selected. Then save the generated file, open it in a text editor, and copy out the appropriate entries. The Bootstrap Manifest Generator tool can also be used to create your own custom packages that are then installed via the ClickOnce bootstrapper.