in

CodePrairie .NET

South Dakota .NET User Group

chrisortman

Using msbuild to create a bootstrapper for you installer

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.

Comments

 

Jason Meridth said:

Awesome post Chris.  Good to know MSBuild has this.  I'm starting to make a full transition to MSBuild due to NAnt not keeping up with the .NET Frameworks.

Have you used WiX in the past?  It also does this for you and you can include it into your Continuous Integration process.

Check it out if you haven't.   The only catch is that it's easier to create a WiX project with SharpDevelop.

I enjoy reading your blog.  Keep'em coming.

April 17, 2008 5:10 AM
 

chrisortman said:

@Jason: I am using Wixv3. I just got done upgrading to the last march build. I didn't know it could do this though. Is it part of an extension?

April 17, 2008 5:39 AM
 

Amy Rosewater said:

Hi Chris,

Thanks for the posting.  I am attempting to modify my msbuild file after a recent upgrade from 2.0 to 3.5, and this is helpful...however, when you say "make sure MSBuild is using the 3.5 ToolsVersion or it won't find the merge modules" do you mean by setting the ToolsVersion attribute of the Project node to "3.5"?

May 6, 2008 12:58 PM
 

chrisortman said:

@Amy yes, or there is a command line switch you can pass, I think it is /ToolsVersion

May 6, 2008 11:45 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
Powered by Community Server (Commercial Edition), by Telligent Systems