Create MSI in Build ScriptsIf you are a software developer you may want to integrate the MSI creation in your build scripts. This is possible using the MsiWrapperBatch.exe program. This program makes is possible to create MSI packages from a command line in batch mode. You can process the configuration XML files that you create and save in the wizard. The basic configurations created with the Wizard can be extended with an extra set of features. These features are only supported in batch mode running from a command line or a build script.
Configuration XML FilesAll configuration settings from the wizard can be saved to an XML file. You can modify the XML to fit your needs in the build script. The extra features in the XML for batch mode execution are described in the text below. This is a real life example of a batch mode configuration file. It is used in a build script to build the MSI file for the Bullzip PDF Printer. The upgrade guid was removed to protect you from reusing it by accident.
Detect AttributeMost values in the configuration file can be read from three different places.
- Configuration file – The value from the configuration file is used if the Detect attribute is missing, empty, or set to Manual.
- Registry – When the Detect attribute is set to Registry the MSI Wrapper will use the values from the registry. In order to use the registry values the program must be installed on the computer before the MSI Wrapper is run. Otherwise, no values can be found. The MSI Wrapper will look in the registry’s uninstall information to get the values for the configuration.
- Executable – Setting the Detect attribute to Executable will make the MSI Wrapper look in the installer executable for the values.
Scanning for Input FilesWhen you create a configuration file from the wizard, you will get an Executable element in the configuration where the FileName attribute points to a file name. Normally you will see the full path of a file in this attribute. In batch mode or build scripts, you may not know the exact name of your executable installer. It is common that the file name of the executable installer contains the version number of the build. To support this type of scenario the MSI Wrapper is capable of scanning a directory for the correct file to wrap. In the example above you will see the attributes Pattern, ScanMethod, and ScanPattern in addition to the normal FileName. These three additional attributes helps the MSI Wrapper to determine which executable to wrap. First of all the FileName attributes contains a wild card instead of a fixed file name. The wild card expression is used to determine the set of files to select from. This selection is narrowed further by the Pattern attribute. After matching the wild card of the FileName attribute, each file name is matched against the regular expression pattern in the Pattern attribute. The ScanPattern attributes contains a regular expression to extract the part of the file names that are compared to each other. When the extracted file name parts are compared, the winner is determined by the ScanMethod attribute value. Valid values are MaxString and MinString. If MaxString is used then the extracted file name part with the highest sort value wins. I will leave it up to you to figure out how the MinString works 🙂
Output File NameIf you leave the Output FileName attribute empty then it will use the name of the executable installer and substitute the .exe extension with a .msi extension. In most scenarios, this is sufficient. However, in some build scripts you may need to change the name of the MSI file based on parts of the file name of the executable installer. This is why you have the Output attributes Pattern and Replace. These are not used in the example above. Using the Pattern and Replace attributes, you can use a regular replace expression to for the file name of the output. The replace operation is done with the full path of the executable installer as input.
Batch ModeWhen you want to run the MSI Wrapper in batch mode, you use the MsiWrapperBatch.exe executable. This program is installed in the MSI Wrapper program folder together with the wizard and other related files. The command line usage is show below.
MSI Wrapper Copyright (c) - EXEMSI.COM DESCRIPTION: This program wraps an executable installer in an MSI package. The process is controlled by a configuration file. You can make a configuration file with the GUI version of this program. USAGE: MsiWrapperBatch.exe [PARAMETERS] Parameter Description ----------------- ------------------------------------------------------------- help Displays this message. config Configuration file name. EXAMPLE: MsiWrapperBatch.exe config="myconfig.xml" EXIT CODES: 0 = Success 1 = ErrorAs shown in the help message the program accepts a configuration file name as the command line switch.