Andrey.Burda
Posts: 23
Joined: Tue Dec 14, 2021 12:06 pm

Temp files are unavailable in sequence Custom Action

Wed Dec 22, 2021 2:42 pm

Hello!

I faced a problem while running EXE file from Temporal files.

This topic has similar problem viewtopic.php?t=47988, but in my case it is a bit different.

I am setting up the Advanced Installer usging Power Shell COM. The goal is to call an EXE program from inline Power Shell script Custom Action, the EXE should be located in temporary files.

Power Shell COM performs the folowing:
$newFolder = $project.PredefinedFolders.Temporary.CreateFolder("DBTool")
$newFolder.Synchronization.SourceFolder = "D:\Demo\DBTool"

As a result of this, in the AIP project I have a DBTool folder and a configured synchronization.
22-12-2021 2-17-50 PM.jpg
22-12-2021 2-17-50 PM.jpg (132.54KiB)Viewed 2297 times
The action I call is a sequence one and it placed after "Install Execution Stage->Preparing". When I run the installer, inline script tries to call an EXE from C:/TEMP/DBTool/program.exe, but "C:/TEMP/DBTool" does not exist at the moment.

When I am adding DBTool folder to temporary files using UI, I see that all the files get added automatically and each file has a unique property like "AI_FILE_NAME". In this case when I run the installer, inline script can call EXE (from C:\TEMP\DBTool\program.exe) as well.

I want the same behaviour by using Power Shell COM. I did not find a method like $project.TempFilesComponent.AddFile , but for folder.

Is there any way to do this?

Thanks in advance!

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

Re: Temp files are unavailable in sequence Custom Action

Wed Dec 22, 2021 4:46 pm

Hello Andrey,

The reason your file is not available at that time is because you did not actually add your files as temporary files.

What you did, i.e. creating the new folder and then synchronizing it with a folder from disk, adds your files as regular files, not as temporary files.

Please note that it is not enough to simply add your files under the "Temporary" folder. In order to add a temporary file, you need to use the "Add Temporary Files" button from the toolbar.

In the article I've linked above, you'll see what temporary files are and the fact that they have a special icon.

Now, in order to add a temporary file using our PowerShell automation support, you can use the ITempFilesComponent.

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

Andrey.Burda
Posts: 23
Joined: Tue Dec 14, 2021 12:06 pm

Re: Temp files are unavailable in sequence Custom Action

Thu Dec 23, 2021 9:56 am

Hi Catalin,

Thanks for the provided information.
I was thinking about the same i.e. files were not actually added as temp files.
Once I move sequence action after "InstallExecute" stage the error has gone. But it was not my case because I have to call an EXE prior the copying of installation files.

The solution that works for me is following: create new folder as Temp, get the list of files from "source" folder and add each file as temp, set correct directory for it.

Code: Select all

if (Test-Path $DBToolFolder) { 
  Write-Host "Adding DBTool to TMP files"
  $newFolder = $project.PredefinedFolders.Temporary.CreateFolder("DBTool")

  Get-ChildItem $DBToolFolder -Exclude *.pdb | 
  Foreach-Object {
    $file = $project.TempFilesComponent.AddFile($_.FullName)
    $file.Directory = $newFolder
  }
}

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

Re: Temp files are unavailable in sequence Custom Action

Thu Dec 23, 2021 10:42 am

You are always welcome, Andrey!

Thank you for sharing your solution with us.

I am glad everything works as expected now.

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

Return to “Common Problems”