A user recently asked me if it is possible to get the version of multiple EXEs and set an installer property to the value of the EXE's version. Something similar with the "Set version from file..." option from the "Product Details" page - when you right click on the "Version:" field.
Although we do not have predefined support for such a task, it is still possible. This is mostly possible with the help of "Pre and Post Build Events", more specifically with the help of a pre-build event. With that being said, I have decided to make a "How-To" for this, in case other users will need this in the future.
Basically, here we will need a PowerShell script (a .BAT file, EXE, VBScript can be used as well) which will:
- take the version from the EXE (EXEs) and store it in a variable (variables).
- further use that variable to set a property to the variable's value using the "/SetProperty" command option.
For the sake of the example, I have used the "RepackagerCLI.exe" and "updater.exe" which are available in every version of Advanced Installer. These can be found in the installation folder of Advanced Installer, at the following path:
For instance, the "updater.exe" path on my machine is the following:
Code: Select all
..\Caphyon\Advanced Installer\Advanced Installer <version>\bin\x86\ExeName.exe
Here are the steps that can be followed in order to achieve this:
Code: Select all
C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\updater.exe
- in "Install Parameters" page, create one property for each of your EXE. E.g.:
both with their values blank. Also, for both, please add comments as this is the only way to "initialize" an empty property.
Below you can find the script that takes the version from an EXE and stores it in a property:
Copy the above script and save it in a PowerShell script file (.ps1). Now please:
Code: Select all
# Script that can be used as a pre-build event in order to get the "Version" attribute of an EXE and store it in a property. We can further use this property # to write the version value in the registries. # As a prerequisite, please create the proeprties in your project with empty values (in order to create a property with an empty value, simply add a comment to it). $AICom = "C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\AdvancedInstaller.com" $projectPath = "C:\Users\Catalin\Desktop\Retrieve version from multiple EXEs.aip" $repackagerPath = "C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\RepackagerCLI.exe" $updaterPath = "C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\updater.exe" # get the version from the Repackager and store it in a variable # the below cmdlet will return a string, which will look something like this: 1, 0, 0, 0. We will further use the "Replace()" method to replace the "," with "." $repackagerVer = (get-item -path $repackagerPath).VersionInfo.FileVersion.Replace(',','.') $updaterVer = (get-item -path $updaterPath).VersionInfo.FileVersion.Replace(',','.') # now that we have got the version of the EXEs, we will further set the properties that we created in our project. Start-Process -FilePath $AICom -ArgumentList "/edit `"$projectPath`" /SetProperty REPACKAGER_VERSION=`"$repackagerVer`"" Start-Sleep -Seconds 2 Start-Process -FilePath $AICom -ArgumentList "/edit `"$projectPath`" /SetProperty UPDATER_VERSION=`"$updaterVer`"" Start-Sleep -Seconds 2 Start-Process -FilePath $AICom -ArgumentList "/save"
- open your project (if it's not already opened)
- go to "Builds" page and create a pre-build event (right click --> "Add" --> "Pre-Build Event" --> "New...")
The event should look like this:
Arguments: -ExecutionPolicy Bypass "&""C:\Users\Catalin\Desktop\VersionScript.ps1"""
Here, you should just replace the path with the path where your script resides.
Now, at Build time, the script will be executed and then the properties will be set. Here are the steps that need to be taken:
- build the project - the pre-build event will take place
- close your project
- re-open your project. At this point, you can check the "Install Parameters" page - here you will notice that the properties were populated accordingly.
- re-build the project. Now the properties will be added in the MSI database as well. Upon install, you can go and check the registries, there you should see the values being set accordingly.
Also, please find below an archive that contains an AIP file and the script which hopefully will help you achieve those said above:
Hope this helps.