Create MSM packages with configurable parameters for custom actions
The following article uses options that are available starting with the Enterprise edition and project type.
In this tutorial, we are going to show the basic concept on how to declare parameters that can be configured when an MSM package is imported in the main Advanced Installer project. For this, we will first build a simple Merge Module package which afterward will be imported into the main project.
In order to show the effect of a Target and Source parameter, we will use a Windows batch command file: batch_file.bat. In this file the following code will be present:
@ECHO OFF ECHO This is a sample batch file. PAUSE
1. Create the Merge Module
- Start a new Merge Module project by selecting from Merge Module tab the "MSM" project type.
- Go to Files and Folders Page and add the created batch_file.bat file.
We will use the Set installer property custom action for which we will configure a Source parameter.
For this type of Custom Action, by modifying the Source parameter, we actually will change the name of the property that holds the Formatted Value.
This Custom Action will set a property that will point at the batch_file.bat location. Based on this location we will later run the file during installation.
- Go to Custom Actions page.
- From the "Add Custom Action" pane select Set installer property and add it in sequence after Add Resources action group.
- In the "Property" field write MY_PROP1
- In the "Value" field write [APPDIR]. This way property MY_PROP1 will point at the installation location.
- From the context menu choose Configurable->Source while the custom action is still selected.
- In the Edit Substitution Parameter dialog push the button and select "New Parameter..." option.
- In the "Name" field write PROP_NAME.
- Set the "Type" field as Text and set the "Default Value" as MY_PROP1.GUID like in the example below. The GUID can be retrieved from the Module Details Page, "Module GUID" field.
MY_PROP1.C094DEC1_30F2_4E08_ABC4_57D17E30E6C0
- Rename the created Custom Action to something meaningful like Set_Property.
For the Target parameter, we will use Launch file custom action. This Custom Action will be then used to show how Source parameter works:
- Add Launch file custom action in sequence after the previously created one.
- Set your custom action to run as deferred
- In the "File To Launch" field write the following: "[MY_PROP1]batch_file.bat" (with the quotation marks).
- From the Launch file custom action's context menu, choose the Configurable->Target option.
- Like before, declare a new parameter LOCATION, select the type Formatted and set the "Default Value" as: "[MY_PROP1]batch_file.bat" (with the quotation marks).
- Untick the options "Uninstall" and "Maintenance" so the custom action runs only during the package installation
- Rename this custom action to something meaningful, like Run_Command.
- Build the MSM project.
The quotation marks (" ") are important. The values in these fields must be written between quotation marks (" ") for the Custom Action to execute properly, otherwise an error will be generated and the package will not install.
2. Create the first main installation package
- Start a new Project (Simple, Professional, etc).
- Go to Merge Modules Page. From the context menu select the Add Merge Module option and select the previously created Merge Module.
- Once the Merge Module is selected the Configure Merge Module dialog appears displaying the MSM parameters.
- For the first build, we will leave all the parameters as they are.
- Add your main application files in the Files and Folders Page.
- Build the package.
- Run the package and notice during the installation process that the batch_file.bat file from the Merge Module is executed.
Because the Custom Action declared in the Merge Module is set as Synchronous execution, check the return code, the installation will finish once the command window is closed.
3. Create the second main installation package
- Start a new Project (Simple, Professional, etc).
- Go to Merge Modules Page. From the context menu select the Add Merge Module option and select the previously created Merge Module.
- Once the Merge Module is selected, the Configure Merge Module dialog appears displaying the MSM parameters.
- Edit the PROP_NAME Parameter by clicking the button located in the down-right side and change MY_PROP1 with MY_PROP2. The result should look like this:
"MY_PROP2.C094DEC1_30F2_4E08_ABC4_57D17E30E6C0"
where C094DEC1_30F2_4E08_ABC4_57D17E30E6C0 is the GUID of the MSM package and is unique for every MSM project.
- Edit the LOCATION Parameter by clicking the button located in the down-right side and change MY_PROP1 with MY_PROP2. The result should look like this:
"[MY_PROP2.C094DEC1_30F2_4E08_ABC4_57D17E30E6C0]batch_file.bat"
where C094DEC1_30F2_4E08_ABC4_57D17E30E6C0 is the GUID of the MSM package.
- Build the package.
- During the installation process, the batch_file.bat file from the Merge Module will run.
As you can see from this tutorial the Source parameter is used to define the property which is used by the Set installer property Custom Action. The Target parameter is used to define the launch parameter (batch_file.bat) used by the Launch File or Open URL custom action.