mstarnaud
Posts: 45
Joined: Mon Apr 15, 2013 9:44 pm

Get folder at build time

Hi

In my latest project, I need to get a folder from somewhere else. But I want to automatically get the latest version when I build. I have a batch file which will do the copy folder operation.

In order to do this, I added the folder once in my project. Then I was able to synchronize it in the Files&Folders window. Then I added a pre-build event that calls the batch file. This way, I expected that before building the Advanced Installer package, the batch file would be executed and collect the latest version of my folder. According to this page http://www.advancedinstaller.com/user-g ... vents.html that's what I thought I should do.

Wrong.

If I look at my build output, it looks like it builds BEFORE calling my pre-build event batch file. If I delete the folder, it will simply refuse to build because the synchronized folder is missing (was not copied by the pre-build event yet).

Here is what it looks like if the folder is already present:
------ Rebuild All started: Project: MyProject Setup, Configuration: Advinst ------
"C:\Program Files (x86)\Caphyon\Advanced Installer 10.2\bin\x86\AdvancedInstaller.com" /rebuild "MyProject Setup.aip" -buildslist AnyCPU_Release
Running C:\Users\mstarnaud\Desktop\myfile.bat... done.
Checking builds status... done.
Build required.
[ AnyCPU_Release ]
Building package (en): C:\Users\mstarnaud\Desktop\SlimUp\Web Container\trunk\MyProject Setup\AnyCPU_ReleaseSetupFiles\MyProject.msi
...and the rest goes here
Here is what it looks like if the folder is deleted:
------ Rebuild All started: Project: MyProject Setup, Configuration: Advinst ------
"C:\Program Files (x86)\Caphyon\Advanced Installer 10.2\bin\x86\AdvancedInstaller.com" /rebuild "MyProject.aip" -buildslist AnyCPU_Release
The source folder "C:\Users\mstarnaud\Desktop\MyFolder" of the synchronized folder "TempFolder" is missing from disk. You need to either recreate the source folder path or reset the synchronization from the "Folder Properties" dialog, in "Synchronize" tab.
C:\Users\mstarnaud\Desktop\MyProject\MyProject Setup.aiproj(44,5): error MSB3073: The command ""C:\Program Files (x86)\Caphyon\Advanced Installer 10.2\bin\x86\AdvancedInstaller.com" /rebuild "MyProject Setup.aip" -buildslist AnyCPU_Release" exited with code 536805277.
Done building project "MyProject Setup.aiproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Any ideas?
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Get folder at build time

Hi,

I'm not sure why you encounter this behavior. Did you try to run the batch file manually to see if it copies the folder that you want to be copied. If so, can you please send us the .AIP (project file) and the batch file to support at advancedinstaller dot com so we can investigate them?

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
mstarnaud
Posts: 45
Joined: Mon Apr 15, 2013 9:44 pm

Re: Get folder at build time

Yes, I tried the batch file manually. The problem is that Advanced Installer seems to run it as a post-build event even if I set it as pre-build (and yes I double-checked it's in pre-build and not post-build). Or, maybe, this is just a guess, the build is done in 2 steps and the pre-build event is called in the middle. The output I pasted in my post above suggests this.

So right now what I do is run the batch file manually before I build. Worst case, I could always find another way to call the batch file at pre-build (Visual Studio or other tools).

I will create and send a sample project soon.
mstarnaud
Posts: 45
Joined: Mon Apr 15, 2013 9:44 pm

Re: Get folder at build time

Reproduction steps:
- Put a folder somewhere with 2 files inside : script1 and script2
- Create the solution, in this case FormsApplication1
- Add the AI project, which will be located at FormsApplication1\AISetpuProject1
- Add a batch file in the solution's folder called GetScripts.bat. It will get the scripts to deploy that come from another project and place them in FormsApplication1\ExternalScripts.
- Run the batch file once.
- Look in the solution's ExternalScripts folder : In my case I had multiple scripts (script1 and script2).
- I deleted script2 to see if the batch file would add it.
- In the AIP, go in the Files&Folders tab.
- Add a folder and synchronize it to the ExternalScripts tab.
- In the Media tab, add a Pre-Build event. The Command is [|AI_AIP_FOLDER]..\GetScripts.bat and the Working Directory is [|AI_AIP_FOLDER]..
- Save AIP file.
- Build AI project. (note that the batch file will be run!)
- Execute the installer.
- Look at the files found in the resulting/deployed ExternalScripts : only Script1 is there.
- Look at the ExternalScripts folder inside the solution : it was updated! Script2 is back!

So to recap:
- If I delete the folder in the solution and build, it crashes before reaching the Pre-Build event (batch file).
- If the folder is present but not up-to-date, the pre-build event (batch file) will be run and the build will "succeed". But the installer will not have the up-to-date folder. Since the batch file did run, the solution will now have an up-to-date folder. But it's too late, I already built!

I will send the sample I created by email.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Get folder at build time

Hi,

I tested you scenario and indeed, I reproduced the behavior. However, the "Pre-build" events are not executed as post-build, the case is that the folder synchronization is done before the pre-build event (synchronization -> pre-build -> build). I'm afraid that this is the normal behavior, the synchronization is done first.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
mstarnaud
Posts: 45
Joined: Mon Apr 15, 2013 9:44 pm

Re: Get folder at build time

Thanks for your answer.

I'm a bit surprised that getting the files cannot be done this way, especially after looking at this page http://www.advancedinstaller.com/user-g ... vents.html
Pre-Build Events
This type of events are executed before the actual package is being created. They can be useful to run commands whose results are used in the package building process, like always copy files from a location to ensure that you always have the latest files included in the project before starting the build process.
It seems to me like the scenario I was trying. But now I guess there should be an asterisk saying it doesn't work with the Synchronize option? Personally, after finding the Synchronize button, I just can't live without it anymore.

I tried to achieve this in Visual Studio. But configuring pre-build and post-build events for projects depends on the project type, and that's not supported for Advanced Installer. So I ended up doing it in my source control / integration tools.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Get folder at build time

Hi

Indeed, our documentation should be updated to warn the users about this case. Thank you for bringing it in our attention.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
louisSchnetler
Posts: 2
Joined: Mon Apr 10, 2017 11:34 am

Re: Get folder at build time

Is there a way to have the copy run before the actual synchronization or not really?
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Get folder at build time

Hi,

I'm afraid that this is not possible from the Advanced Installer GUI. A solution to achieve this, is to build your package from command line and copy the necessary files from the same script, before the build starts.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”