I stumbled upon a nice task in MSBuild that you can use to create an executable file to
install prerequisites for your application. I used to do this in the past with by just creating a Setup Deployment project setting prerequisites and holding onto the generated .exe
The biggest problem with that was that it made it problematic to ship an installer with the version number in the filename since the setup.exe was bound to an msi filename.
Using the GenerateBootstrapper task I can create this setup.exe file as part of my build process.
Take a look at this snippet from one of my build files
<ItemGroup>
<BootstrapperFile Include="Microsoft.Net.Framework.3.5">
<ProductName>Microsoft .NET Framework 3.5</ProductName>
</BootstrapperFile>
<BootstrapperFile Include="Microsoft.Sql.Server.Express.9.2">
<ProductName>Microsoft SQL Server Express 2005 SP2</ProductName>
</BootstrapperFile>
<BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
<ProductName>WIndows Installer 3.1</ProductName>
</BootstrapperFile>
</ItemGroup>
<Target Name="CreateBootStrapper">
<Message Text="$(GenerateBootstrapperSdkPath)" />
<GenerateBootstrapper ApplicationFile="$(OutputName).msi"
ApplicationName="$(ProductName)"
BootstrapperItems="@(BootstrapperFile)"
OutputPath="$(OutputPath)"
ComponentsLocation="HomeSite"
Culture="en-US" />
</Target>
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn);CreateBootStrapper</BuildDependsOn>
</PropertyGroup>
The BootstrapperFile items define my prerequisites. The easiest way I found to see what the list of available prerequisites are was to create a Setup Deployment project and configure them, then look at the generated project file
Then all I need to do is invoke the task and boom, setup.exe is produced.
One thing I did run into when doing this is that you have to make sure MSBuild is using the 3.5 ToolsVersion or it won't find the merge modules.
Also, the referenced prerequisites seem to only get installed with Visual Studio so I had to install it on my build server.