Visual Studio: Conditionally Create Shortcuts in Setup Project?

Donut picture Donut · Oct 8, 2009 · Viewed 7k times · Source

I am working on a Setup Project in Visual Studio, and I would like the user to be able to specify whether to create a Desktop Shortcut and/or a Start Menu shortcut to the program by using checkboxes.

I am able to have the installer to create working shortcuts in the appropriate locations, and I added a dialog containing checkboxes to the installer; however, I am unable to have the creation (or lack thereof) of these shortcuts connected to the status of these checkboxes.

I'm assuming that I need to set "Condition" properties, but I'm not sure of the specific syntax. Is this possible, and if so, how would I go about accomplishing this?

Answer

Cheeso picture Cheeso · Oct 12, 2009

The linked feedback item said:

In the case that you want the checkbox to only control whether the shortcut installs, and not its target, there is currently no solution in Visual Studio setup projects, and this is best accomplished either through extra MSI knowledge and a post-build script to manually modify your MSI after each build, or by migrating to a more advanced (and flexible) tool for setup development (for example, Windows Installer XML).

You can't do it within the VS point-and-click interface, but it's actually not difficult to do what you want with a simple custom action.

alt text

Define a script, in VBScript or JavaScript. You can set the custom action to run based on any condition, including a checkbox in a dialog.

alt text

Inside the script, you parse the input, and create the shortcut. I used the convention to separate args to the script with a | character, so this is how I parse:

var parameters = Session.Property("CustomActionData").split("|"); 
var targetDir = parameters[0];
var checkBoxState = parameters[1];