How can I customize an MSI in the Visual Studio setup/deployment project?

  
Aaron Stebner's WebLog -

Question:

I am using the Visual Studio setup/deployment project to create an MSI to install my application.  I would like to add some functionality to this MSI that does not appear to be supported in the Visual Studio IDE (such as modifying the default install path based on a registry value on the system).  I know how to do this by directly editing the MSI, but I don't want to have to manually edit the MSI each time I build.  Are there any other options I can use in this scenario?

Answer:

There is a limited set of customizations you can make to an MSI in the Visual Studio IDE UI for a setup/deployment project.  By limited, I mean that there are a lot of features that are natively supported in Windows Installer MSI format that are not exposed for customization in the Visual Studio IDE.  Examples include changing the default install path based on a registry value, advanced setup UI features such as updated banner text or a "launch my product" checkbox on the final screen, creating custom actions that reference external executable files, or setting various custom action attributes (among other things).

If you would like to automate the ability to customize an MSI that is built by the Visual Studio setup/deployment project in a way that is not currently supported by the UI in the Visual Studio IDE, you can write a script that accesses the Windows Installer object model to perform these customizations.  Then you can create a post-build step in your Visual Studio setup/deployment project to run your script after the MSI has been built so that the final result each time you build will be an MSI package with your additional customizations made to it.

As an example, you can use the sample script at this location to add a checkbox to your MSI's setup UI that will let the user choose whether or not to launch your product after setup finishes.

If you would like to include this script as a post-build step in a Visual Studio setup/deployment project, you can use the following steps:

  1. Download the sample script and extract the contents to the directory that contains the Visual Studio project you are working on
  2. Open the project in Visual Studio
  3. Press F4 to display the Properties window
  4. Click on the name of your setup/deployment project in the Solution Explorer
  5. Click on the PostBuildEvent item in the Properties window to cause a button labeled "..." to appear
  6. Click on the "..." button to display the Post-build Event Command Line dialog
  7. Add the following command line in the Post-build event command line text box:
    cscript.exe "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOutputPath)"
  8. Build your project in Visual Studio

Note that the quotation marks in the command line in step 5 are very important because the script will not work correctly without them.  Make sure to double-check that you have put quotes in the proper places.

You can find another example script that will update the MSI setup UI banner text in this MSDN forum post.

Updated the steps needed to configure post-build commands in the Visual Studio UI because they are different for setup projects than for other Visual Studio project types

 

 
Published Friday, August 25, 2006 9:19 AM by dotnetboy2003

Comments

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

You are a legend, I finally found this after looking for what felt like an age!!

Friday, September 1, 2006 10:27 AM by Peter

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

Worth noting the macro name is actually: 'BuiltOuputPath'. Also don't forget to rename the .js file.

Friday, September 1, 2006 10:36 AM by Peter

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

Could you please post this js file somewhere that people can reach?  The link above is broken.  The enable launch application information is great, but without that script pretty useless.  How about posting the script?  It shouldn't be that big right?

Friday, February 16, 2007 8:13 AM by Jason Short

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

am getting teh following error after doing the things u said

'PostBuildEvent' failed with error code 1 "unspecified error"

I want to alunch my app with a checkbox after installation is completed

Friday, July 18, 2008 7:54 AM by nit

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

thanks, was too hard to find this!!

Tuesday, September 2, 2008 12:41 PM by mike

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

This didn't do anything. There was no screen with Launch checkbox after compiling my new install.

Monday, November 17, 2008 9:12 PM by Rory Groves

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

The post-build command doesn't work. When I bring up the post-build script editor and click Macros, I notice that Visual Studio has mispelled it. The macro name is $(BuiltOuputPath) - IT IS MISSING THE LETTER T. This is on Vista with Visual Studio 2008. I'm not sure if this problem affects other versions of VS or Windows.

You say "Note that the quotation marks in the command line in step 5..." I think you mean step 7. Anyway it isn't working for me.

Friday, December 5, 2008 3:31 PM by Justin

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

My application requires elevated privileges on Vista and displays the UAC prompt. The script above doesn't seem to work in this case. It does not launch the application. The installer was already running elevated, so I don't know what the problem is.

How do I get this to work with an application that requires elevated privileges on Vista?

Friday, December 5, 2008 4:11 PM by Justin

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

This doesn't work on Vista with an application that requires elevated privileges. If there is no way to make this work on Vista in this case, how can I make one MSI where the check box appears on XP but the check box does not appear on Vista. Otherwise my installer will look broken to the customer because they've chosen to "Launch myapp.exe" but it doesn't launch.

Friday, December 5, 2008 4:16 PM by Justin

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

I'm not able to open sample script at this location  and sample script to download

Wednesday, March 11, 2009 4:16 PM by thuan022460

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

Could you please publish EnableLaunchApplication.js file for downloading?  The current link is N/A when clicking on Sample Scripts.  I would like to try cscript.exe "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOutputPath)" since I'm not able to launch the app from shortcut when using Setup / Deployment project to create MSI package from VS 2008.

Thanks,

Thuan

Thursday, March 12, 2009 1:44 PM by thuan022460

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

Hello

I want to add 2 option for check in finish page. Do you have an exemple for this?

Tuesday, February 2, 2010 9:05 AM by Ovidiu

# re: How can I customize an MSI in the Visual Studio setup/deployment project?

How can i insert a checkbox and textbox on a single dialog box say Finished dialog box in the Visual Studio setup/deployment project?

Thursday, August 12, 2010 6:09 PM by saurabh