Using compiler variables to customize setup at build time

Hello everyone, I hope you’ve all been well!

This post’s topic: How to customize your setup at build time. This could be used for different products, when only very few things change between them, and having a unique setup project for each one turns into a major copy and clone nightmare. It’s really a quite common scenario to have similar products using similar setup routines. At InstallAware, we actually ship a single installer that contains all four of our product editions – allowing users to choose at runtime which version they want to install. We might cover that in a later post; for now we’ll look at how to customize your installations at build time – emitting multiple “flavors” of a setup, if you will. This is where Compiler Variables come into play.

Compiler Variables are defined inside the Project Options window. To bring up this window, click the Project Settings button, found inside the Manage group of the Design tab.

Choose the Compiler Variables section and you’ll see three buttons, Add, Edit and Delete. This is where you define and set the initial values of your Compiler Variables. These variables are accessed using the #COMPILER_VARIABLE_NAME# format inside your MSIcode script. You may use these variables anywhere inside your script. Even MSIcode command fields which do not ordinarily accept variables will take compiler variables, since compiler variable values are “burnt-in” at build-time, and do not change at runtime.

In addition to replacing literals with values injected at build time, another use of compiler variables is to conditionally include/exclude parts of your MSIcode script. Use the Compiler Variable If, Compiler Variable Else and Compiler Variable End MSIcode commands to include/exclude parts of your setup project at build time. This adds a lot of flexibility to how you can build setups at runtime – you can take out whole blocks of MSIcode script, completely changing your setup logic and files – all at build time, and without needing to use complex automation.

Here’s a short list of what you can customize with compiler variables, among other things:

  1. Product name
  2. Product version
  3. Product code
  4. Files being installed
  5. Features being built

Take look at the code below to see what I mean:

As you can see, one of my compiler variables is “MYPRODUCT” and its defined/initialized on the Compiler Variables section of the Project Options window. The above code builds some files and features if the compiler variable “PRODVERSION” is equal to “Enterprise” but excludes one file if the compiler variable “SUBVERSION” is not equal to “Full”.

You might also want to take a look at the pre-defined compiler variables that already exist in InstallAware. There are two kinds of pre-defined variables – pre-defined compiler variables and pre-defined script/runtime variables – so don’t get confused between the two. Both of these pre-defined variable kinds come in real handy for lots of things, like figuring out the execution path of your setup. I’d definitely encourage you to take a look at them. Just search for pre-defined variables and pre-defined compiler variables in the help index.

My favorite compiler variables are the following:

  1. LOADOLDDATA: Instructs the setup engine to migrate feature selections from older versions.
  2. PROJDIR: Resolves to the project directory on your system.
  3. LOADOLDDATA: Instructs setup to change the way in which localizations are applied at runtime (see the help file for details).
  4. BUILDMODE: Resolves to CD, SFX, WEB, or PATCH based on your setup build mode.
  5. TITLE: Resolves to the name of the setup project.

Thank you,

Panagiotis Kefalidis
Software Design Team Lead
InstallAware Software Corporation