jakub
Posts: 6
Joined: Thu Aug 26, 2021 9:53 am

Change versioned folder name at build time

Thu Aug 26, 2021 12:31 pm

I would like to change folder name which contains version at build time, similar to what is proposed here: viewtopic.php?t=40913#p109806. The difference is I do not want to use ProductVersion property, since in my case it does not contain build timestamp, which I want to include only in the versioned folder. Is there a way to do that?

Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Change versioned folder name at build time

Fri Aug 27, 2021 1:11 pm

Hi,

If I understand correctly, you want to change the folder name to contain the timestamp at build time.

You can do that with a PowerShell script (a .BAT file, EXE, VBScript can be used as well) which will set the time into a variable.

Below you can find the script that saves the timestamp in a property:

Code: Select all

# Script that can be used as a pre-build event in order to get the time and save it in a property
# As a prerequisite, please create the property 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 18.5\bin\x86\AdvancedInstaller.com"
$projectPath = "C:\Users\Midn1ght\Desktop\timestamp pre build\Your Application.aip"

$timestamp = (Get-Date).ToString("yyyy_MM_dd_HH_mmss")

Start-Process -FilePath $AICom -ArgumentList "/edit `"$projectPath`" /SetProperty TIMESTAMP=`"$timestamp`""
Start-Sleep -Seconds 2
Start-Process -FilePath $AICom -ArgumentList "/save"
Please update the $AICom variable to the path of your current AI version and $projectPath variable to your current project.
Copy the above script and save it in a PowerShell script file (.ps1).

Now please follow these steps:
  1. Go to the “Properties” page and add a new property, for example “TIMESTAMP”.
  2. From the “Builds” page, select your build and on “Configuration” tab change the folder output to:

    Code: Select all

    “[|ProductName]_[|TIMESTAMP]”
  3. Now, on “Builds Events” tab create a pre-build event (right click → "Add" → "Pre-Build Event" → "New...")
    The event should look like this:

    Command: powershell.exe
    Arguments: -ExecutionPolicy Bypass "&"""C:\Users\Midn1ght\Desktop\timestamp.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. In the below screenshot is the result:
timestamp.jpg
timestamp.jpg (15.46KiB)Viewed 11475 times
Also, attached you can find an archive that contains the .AIP file and the script which hopefully will help you.

If you have any other questions, please don't hesitate to contact us!

Best regards,
Liviu
Attachments
sample project.zip
(3.72KiB)Downloaded 352 times
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

jakub
Posts: 6
Joined: Thu Aug 26, 2021 9:53 am

Re: Change versioned folder name at build time

Mon Aug 30, 2021 11:18 am

Hi,

Thanks for quick reply.

What I meant is not to change build output folder name, but to change a folder name within an installer (which is subfolder of APPDIR in my project), so that after running the installer on target machine the folder name contains a version with timestamp.

For that purpose I've only managed to use predefined Windows Installer Properties, like ProductVersion. If I try to set a folder name to resolve custom property, e.g. InstallerVersion, a tooltip appears saying a "|" character cannot be used in a folder name:
screenshot.jpg
screenshot.jpg (158.04KiB)Viewed 11386 times

Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Change versioned folder name at build time

Wed Sep 01, 2021 9:11 am

Hi,

By default, properties referenced by PseudoFormatted ("[|propertyname]") field are resolved at build time. During installation only properties used in Formatted data fields are resolved.

To achieve what you want, you can create a "Property-Based Folder". Please follow these steps:

1. Go to the "Properties" page and add 2 new properties:
  • Name: TIMESTAMPFOLDER
  • Value: C:\
  • Name: TIMESTAMP
  • Value: Your Value
2. From the "Files and Folders" page, add a new "Property Based" folder and select "TIMESTAMPFOLDER" property. I also created the following folder structure:
PropertyFolder.png
PropertyFolder.png (35.77KiB)Viewed 11238 times
3. Go to the "Custom Actions" page. Add two "Process data" custom action with sequence, and move them on "Install Execution Stage" after "Searches" action. We need this custom actions to format the date property because folders do not allow ":" and "/" in their names.
Configure the custom actions like this:
processData1.png
processData1.png (41.56KiB)Viewed 11238 times
processData2.png
processData2.png (43.12KiB)Viewed 11238 times
4. Now add a "Set installer property" custom action with sequence after the second "Process data" custom action.
setProperty.png
setProperty.png (45.19KiB)Viewed 11238 times
As you can see, in the value field you can add the path where you want to install your property based folder.

This is the result after the installation. The time and date are added based on the Regional format used on the machine. For example, if I change my computer date format to "01-Sep-21", now the folder will be "data_01-Sep-21_105329"
result.png
result.png (6.19KiB)Viewed 11238 times
Attached is the .aip (project setup) file which implements this.

Hope this helps!

Best regards,
Liviu
Attachments
Your Application.aip
(16.49KiB)Downloaded 371 times
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

jakub
Posts: 6
Joined: Thu Aug 26, 2021 9:53 am

Re: Change versioned folder name at build time

Thu Sep 02, 2021 8:09 am

Hi,

Thanks for detailed explanation. I am wondering if there is any way to do that without custom actions? If I use APPDIR directly in property initial value, which is used by property based folder, it is not resolved.

BR,
Jakub

Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Change versioned folder name at build time

Thu Sep 02, 2021 12:16 pm

Hi Jakub,

Unfortunately, there is no other way to do that. During the install time you can set the timestamp only with the custom actions.

Let me know if there is anything else I could help you with.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”