We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

tmwoods
Posts: 11
Joined: Thu Dec 19, 2019 10:32 pm

Property in Custom Action using name, not value

This is a bit confusing to explain, but I have a problem where a property being retrieved in a C# custom action is using the name of the variable instead of the value. What is strange though is that I can see in the log it has the correct value, but when I use it then it uses the property name.

Here is an example:

Code: Select all

        [CustomAction]
        public static ActionResult UpdateConfigPaths(Session session)
        {
            // Get values from session data
            string installPath = session["APPDIR"];
            string connPath = session["CONFIGDIR"];
           
           // Log values
            session.Log("UpdateConfigPaths BEGIN");
            session.Log("installPath: " + installPath);
            session.Log("connPath: " + connPath);
In the logs I see:
UpdateConfigPaths BEGIN
installPath: C:\Program Files (x86)\myInstallPath\myProgram\
connPath: C:\Program Files (x86)\myInstallPath\myProgram\Configuration
This is 100% good so far.

Later I use the `installPath` variable to loop through directories, which works. But I try to update a string inside a config file with the value `connPath` and I get the following:

Code: Select all

itemElement.SetAttributeValue("file", string.Format(@"{0}\AppSettings.config", connPath));
But the result is:
<appSettings file="[APPDIR]\Configuration\AppSettings.config">
I have no idea why it is replacing `C:\Program Files (x86)\myInstallPath\myProgram\` with `[APPDIR]`.

Can anyone tell me what I'm doing wrong here?
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Property in Custom Action using name, not value

Hello,

To be fully honest with you, I can not say for sure why this happens.

However, at a first glance, I noticed the following:

- basically, the connPath variable is set to this:

Code: Select all

[APPDIR]Configuration
This makes me think that your CONFIGDIR property is built upon the APPDIR property. This can be done, for instance, by using a "Set property" custom action which sets the value of the CONFIGDIR property to the "[APPDATA]Configuration" value (without quotes).
Later I use the `installPath` ...
Here, could you please elaborate a bit on what you mean by "later". Does it mean later in the same custom action (where the variables are created), or perhaps it means later as in another custom action scheduled at a later point (where you try to recreate the variables by assigning them values)?

As it can be seen, in the custom action, the value is basically is basically replaced with "[APPDIR]\Configuration". This might be related to what I've said above (the fact that the CONFIGDIR property is based on the APPDIR property value).

The quickest fix I can think of right now would be to create the "connPath" variable based on the "installPath" variable. For instance, you can concatenate the "installPath" variable with the "Configuration" value and this would result in the desired path.

However, in order for me to further investigate this, could you please forward me, by e-mail at support at advancedinstaller dot com, the following resources:

- a copy of the .AIP file

- a download link for the setup

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
tmwoods
Posts: 11
Joined: Thu Dec 19, 2019 10:32 pm

Re: Property in Custom Action using name, not value

I replaced the [APPDIR] references and just built the paths in my custom action and the problem went away.

It is still a mystery why they would log properly but fail in a loop, but so it goes.

Thanks,
Trevor
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Property in Custom Action using name, not value

Hello Trevor,

Thank you for your followup on this.

I am glad you managed to solve this issue.

Please let me know if there is anything else I could help you with and I will gladly assist.

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

Return to “Building Installers”