SZLMCL
Posts: 26
Joined: Mon Nov 16, 2020 2:18 pm

Automatize installer creation with PowerShell

Thu Jan 26, 2023 12:46 pm

Hello,

I have an existing AI installer.

I would like:
1. Increase the version with 1 (generate new guid).
2. ReBuild the installer.
3. Save the project file.
with PowerShell.

This is possible? or there are another ways to automatize this tasks?

Thank you!

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Automatize installer creation with PowerShell

Thu Jan 26, 2023 12:57 pm

Hello,

Yes, that is possible.

In order to achieve that, please proceed as it follows:

Code: Select all

$advinst = new-object -ComObject AdvancedInstaller
$project = $advinst.LoadProject("C:\Users\Catalin\Desktop\Your Application.aip")
$prodDetails = $project.ProductDetails
$prodDetails.Version = "1.0.1"
$project.Rebuild()
$project.Save()
Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

SZLMCL
Posts: 26
Joined: Mon Nov 16, 2020 2:18 pm

Re: Automatize installer creation with PowerShell

Thu Jan 26, 2023 1:53 pm

This is amazing, than you very much. It works!

That is also possible to automate the build of "Updater" project?

Image

Thank you!
Attachments
img1.png
img1.png (34.25KiB)Viewed 24404 times

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Automatize installer creation with PowerShell

Thu Jan 26, 2023 3:03 pm

Hello,

Yes, it would be possible to edit the Updates Configuration File, through the IUpdatesProject interface.

This is quite similar with what we've previously done.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

SZLMCL
Posts: 26
Joined: Mon Nov 16, 2020 2:18 pm

Re: Automatize installer creation with PowerShell

Thu Jan 26, 2023 5:21 pm

Thank you!

I try write the code, but my first command will not work. :-)

1. Delete all existing updates:

foreach ($iupdate in $project.Updates) {
$project.RemoveUpdate $iupdate
}

Throws error:

+ $project.RemoveUpdate $iupdate
+ ~~~~~~~~
Unexpected token '$iupdate' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken

Do you have any idea what I making wrong?
Thank you!

SZLMCL
Posts: 26
Joined: Mon Nov 16, 2020 2:18 pm

Re: Automatize installer creation with PowerShell

Thu Jan 26, 2023 5:24 pm

Sorry I have a mistake with PS syntax, now works.

SZLMCL
Posts: 26
Joined: Mon Nov 16, 2020 2:18 pm

Re: Automatize installer creation with PowerShell

Thu Jan 26, 2023 6:27 pm

Finally I succeed with this. I post my code, probably help for anyone.
The only thing that I cannot find in object model is the updates.txt file location. Can you help me please how can I get this? Thank you!

Code: Select all

# Delete all update definitions
foreach ($iupdate in $project.Updates) {
   $delres = $project.RemoveUpdate($iupdate)
}

Write-Output "Előző frissítési beállítások törlése befejeződött."

# Add new project
$folder = "a:\INSTALLER"
$latestInstaller = (Get-ChildItem -Path $folder | Where-Object { $_.Name -like "*XY_Setup*.exe" } | Sort-Object LastWriteTime -Descending)[0]

$newres = $project.NewUpdate("Update",$latestInstaller.FullName)
if ($newres) {
	Write-Output "Új telepítő sikeresen hozzáadva."	
	
	$project.Updates[0].Properties.MainUrl = "https://xy.blob.core.windows.net/installers/download/" + $latestInstaller.Name
	Write-Output "","Beállítások",""
	Write-Output $project.Updates[0].Properties.MainUrl 
	
	$date = Get-Date
	$day = "{0:dd}" -f $date
	$month = "{0:MM}" -f $date
	$year = "{0:yyyy}" -f $date
	
	$project.Updates[0].Properties.ReleaseDate = "$day/$month/$year"
	$project.Updates[0].Properties.DisplayName = $project.Updates[0].Properties.DisplayName + " - " + $projversion
	
	Write-Output $project.Updates[0].Properties.ReleaseDate
	Write-Output $project.Updates[0].Properties.DisplayName
	
	$project.Updates[0].ReleaseNotes.BugsFixed = $null
	$project.Updates[0].ReleaseNotes.Description = $null
	$project.Updates[0].ReleaseNotes.Enhancements = $null
	$project.Updates[0].ReleaseNotes.Features = $null
	
	$project.Updates[0].InstalledDetection.Options.Search64BitLocations = $true
	
	$project.Save()	
	$project.Build()
} else {
	Write-Output "Hiba történt az új telepítő hozzáadása közben."
}

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Automatize installer creation with PowerShell

Fri Jan 27, 2023 11:31 am

Hello,

Thank you for your followup on this and for sharing the code with us.

I am sure this will be helpful for other users facing a similar scenario. :)

Regarding your last question, I'm afraid I'm not quite sure I understand it. The updates.txt file should be built relative to the "Updates Configuration File" project.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”