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

Update a file from Files and Folders during installation

Fri Dec 31, 2021 11:53 am

Hello!

I have a specific problem: i am using a couple of custom actions (inline PS scripts) to calculate\set variables after user selects installation path and i want to update some file before it will be installed (moved to target directory).

The below setting (web.config file) should be upated to a variable that calculated by inline PS script:

<appSettings>
<add key="visionblue.exe.path" value="MY_VARIABLE" />
</appSettings>

Basically, target folder will have a couple of already installed Web services (by separate installer) with their own web.config files, so I cannot update configs in target foder after installation to not break previously installed services.

The updates required only for those services, that are a part of "Files and Folders" section:
31-12-2021 1-40-18 PM.jpg
31-12-2021 1-40-18 PM.jpg (92.68KiB)Viewed 2082 times
I tried to use a folder name from the above screen - "ClaimsServiceAPI_Dir", but it does not exists for a moment.
Also, i tried to use APPDIR folder and get a list of files under it, but my source files (from "Files and Folders") are not yet there because install process is not yet started i.e. user did not click "Install" button.

So I wonder how can I update some source file while installation (or before user clicks "Install")?

I was thinking about subscribing some event that occurs when file moves to a target folder, so I can update it beforehand.

Regards,
Andrey

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

Re: Update a file from Files and Folders during installation

Mon Jan 03, 2022 4:28 pm

Hello Andrey,

Not quite sure I fully understand your scenario here.

However, if it is what I believe, then you might proceed as it follows:

- add the configuration file (the .XML file) using the "Windows Installer Format"
WindowsInstallerFormat.png
WindowsInstallerFormat.png (23.86KiB)Viewed 2008 times

- the above will allow you to manipulate the XML entries by using installer properties
Value.png
Value.png (63.85KiB)Viewed 2008 times

For instance, if you double click "value" element, you will be able to insert a property in the "Value" field

That property should be set by your PowerShell scripts. When doing that, at installation time, when the XML file is copied on the disk, the installer will check for the value of the property and provide that for the element.

Hope this helps!

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: Update a file from Files and Folders during installation

Mon Jan 10, 2022 9:48 am

Hi Catalin,

Thanks for the answer, but it is a bit different scenario.

I have a config file (Web.config) that will be added dynamically to *.aip by Power Shell COM:

Code: Select all

$project.FilesComponent.AddFolderContents("APPDIR", $sourceFolder)
Before installation process (copying files to target folder), I want to update Web.config file (in my case by .NET Custom Action that requires a path to a file to open it, update and save), therefore the installer will copy an updated version to a target folder.

I am mixing up two approaches: i have a list of empty hardcoded folders in "Files and Folders" in *.aip project and a Power Shell COM line that actually fills in the content of folders, so I cannot update the config file "manually" because it does not exist in *.aip project.

It does not matter what type of config file, I want to find a way how to access it before source files get copied to target folder (installation folder), because as I explained in the initial question, if I try to find this file under "ClaimsServiceAPI_Dir" - it does not exist untill "Finish" installation step.

Wondering how to do that?

Regards,
Andrey

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

Re: Update a file from Files and Folders during installation

Wed Jan 12, 2022 4:20 pm

Hello Andrey,

Well, I think the only solution here would be adding your files as temporary files.

Unlike Advanced Installer's regular files or resources, "Temporary Files" are copied on the target machine at the beginning of the installation and are deleted at the end of it, ensuring you have access to them throughout the entire install process.

Otherwise, it would be impossible to access the file at the start of the installation since the files are copied on the machine during the "Add resources" action group. The "temporary files" support was created specifically for scenarios like yours, when there is a need to copy a file on the machine earlier.

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: Update a file from Files and Folders during installation

Thu Jan 13, 2022 3:55 pm

But what if I need updated files being copied to the target folder?

If I add files as temp files, how can I access them to copy to target directory?

Regards,
Andrey

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

Re: Update a file from Files and Folders during installation

Fri Jan 14, 2022 3:35 pm

Hello Andrey,

You can copy the files through a Custom Action.

However, please note that the custom action should be scheduled after the "Add resources" action group, with the "Execution time" set to "When the system is being modified (deferred)" (since that is the time where files are copied on the machine and therefore the folders are created).

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: Update a file from Files and Folders during installation

Tue Jan 18, 2022 9:23 am

Thanks, Catalin!

I will try this.

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

Re: Update a file from Files and Folders during installation

Tue Jan 18, 2022 11:09 am

You are always welcome, Andrey!

Let me know if you encounter any issues and I will gladly assist.

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: Update a file from Files and Folders during installation

Fri Jan 21, 2022 4:00 pm

Hi Catalin.

I am having access problems with Temporal folder's file.

I specified the following instructions using Power Shell COM interface:

Code: Select all

$newFolder = $project.PredefinedFolders.Temporary.CreateFolder("CreditorServiceAPI")
$newFolder.Synchronization.SourceFolder = 'D:\Demo\a\Apps\CreditorServiceAPI'
As the result, I have a temporal folder in Temp files in *.aip project:
21-01-2022 5-56-31 PM.jpg
21-01-2022 5-56-31 PM.jpg (247.72KiB)Viewed 1645 times
I want to call an EXE file from the above screen before any source files will be copied to target folder in case to break up installation process if error occurs while EXE executing (in fact it is an .NET Core Code First migrations App).

I have added Power Shell inline script and place it in a sequence before "Add Resource" step (Execution time = Immediately):
21-01-2022 5-50-47 PM.jpg
21-01-2022 5-50-47 PM.jpg (14.49KiB)Viewed 1645 times
Inside this script I have the following instructions:

Code: Select all

$Path = AI_GetMsiProperty CreditorServiceAPI_Dir

 Write-Output "Path is $Path"

if ($Path -ne '') {
  Get-ChildItem $Path -Include *.exe -Recurse | 
  Foreach-Object {
  Write-Output "FullName is $_.FullName"
  }
exit 0
}
When I run the installer, the error says that folder (or it content) does not exist:
Get-ChildItem : Cannot find path 'C:\TEMP\CreditorServiceAPI\' because it does not exist.
Is there a way to access EXE from the Temporal folder by inline Power Shell action or any other?

Regards,
Andrey

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

Re: Update a file from Files and Folders during installation

Wed Jan 26, 2022 4:10 pm

Hello Andrey,

The problem here might be the fact that your files are not actually added as temporary files. I am not quite sure your approach is correct here, i.e.:

- first creating the folder

- then synchronizing it with a folder from the disk

This way, I don't believe the files are actually added as temporary files.

Since the icons of the files are covered, I can not really say for sure if this is the case. Temporary files have a special icon to themselves, as in the following article:

Temporary Files Operations in the Files and Folders Page

If that is the case, then the fact that your PS custom action fails is normal, since the folder indeed does not exist.

To fix this, please try the following approach:

- remove the folder from your project

- now expand "Add temporary files" from the toolbar and select "Add temporary folder"

AddTempFolder.png
AddTempFolder.png (89.39KiB)Viewed 1580 times

This way, you can ensure the files are added as temporary files and thus the custom action should now be successful.

For now, it looks like our PowerShell automation only supports adding a temporary file, not a folder. I will add this on our TODO list of improvements and hopefully it will be available in a future version of Advanced Installer.

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: Update a file from Files and Folders during installation

Thu Jan 27, 2022 3:49 pm

Hi Catalin,

I thought that the line below adds a folder as Temp folder, because *.aip project does not contain it if I am not running PowerShell COM configuration script:

Code: Select all

$newFolder = $project.PredefinedFolders.Temporary.CreateFolder("CreditorServiceAPI")
I understand your suggestion, but I cannot use UI to add a Temp folder and files - it is essential to add the content dynamically.

Regards,
Andrey

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

Re: Update a file from Files and Folders during installation

Mon Jan 31, 2022 9:50 am

Hello Andrey,

No, that will not create a temporary folder.

In order for a file to be added as a temporary file, it should have the "TemporaryFile" type (and also a specific icon). As you can see, your file is of "Application" type.

Unfortunately, for now, it is not possible to do that with our current PowerShell support.

I believe what you want to achieve is possible, however, with a little bit of manual work:

- create the folder

- in your PowerShell script, loop through each object from your disk folder and then add it as a temporary file in your Advanced Installer project.

As mentioned above, I have already added this improvement on our TODO list and hopefully it will be added in a future version of Advanced Installer.

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: Update a file from Files and Folders during installation

Tue Feb 01, 2022 11:20 am

Hi Catalin,

Thanks for the clarification.

Regards,
Andrey

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

Re: Update a file from Files and Folders during installation

Tue Feb 01, 2022 2:04 pm

You are always welcome, Andrey!

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

Return to “Common Problems”