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
 

Divya Mohan Singh said:

hi chrish,

m newbie for this. and i want make a bootstrapper for my installer.which check(if not install them) for some prerequisites and then install my application's installer..

Now m making a setup project from setup and deployment projects..but my question is that where i can use that snippet which u mentioned above ..plzz guide me.

thanx

August 30, 2009 11:59 PM
 

Developing MSI with MSBuild said:

Pingback from  Developing MSI with MSBuild

October 2, 2009 10:43 PM
 

Ashish said:

GenerateBootstrapper was a good suggestion. Looks like it is working on Windows7 OS. I have created a bootstrapper which will check/download/install .Net 3.5 followed by the installation of MSI.

For unit testing, i ghosted an XP machine – uninstalled .Net3.5 SPI component . When i double click the setup.exe it is giving error ” setup.exe is not a valid Win32 application”. Any suggestions !

May 9, 2013 3:17 PM

Leave a Comment

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