Yesterday, I've looked at changing INSTALLFOLDER in a custom action for a WIX 3.7 installer project.
As installer technology is not my usual daily thing, the Web was the first resource. I've looked at a few of the related posts, where most of them advising that the action should be invoked after CostInitialize step or similar. This might be useful for other properties, but not for INSTALLFOLDER, as the installer apparently used the default value and installed the product in the default location.
After trying a few spots in the InstallExecuteSequence with the same result, I've ultimately logged the install run, which showed that the custom action was invoked too late, i.e. after target locations for the components were already set based on the default INSTALLFOLDER.
After looking at Suggested InstallExecuteSequence, on the MSDN library site, I've decided to execute it at the earliest available location i.e. before LaunchConditions. And it worked!
Below is the snippet of the code from the .wxs file
and here is a snippet of the code in the custom action:
The thing that I don't like is that it also overrides user overrides via msiexec command line arguments, but it wasn't an issue this time...
As installer technology is not my usual daily thing, the Web was the first resource. I've looked at a few of the related posts, where most of them advising that the action should be invoked after CostInitialize step or similar. This might be useful for other properties, but not for INSTALLFOLDER, as the installer apparently used the default value and installed the product in the default location.
After trying a few spots in the InstallExecuteSequence with the same result, I've ultimately logged the install run, which showed that the custom action was invoked too late, i.e. after target locations for the components were already set based on the default INSTALLFOLDER.
After looking at Suggested InstallExecuteSequence, on the MSDN library site, I've decided to execute it at the earliest available location i.e. before LaunchConditions. And it worked!
Below is the snippet of the code from the .wxs file
<CustomAction Id="SetINSTALLFOLDER" BinaryKey="CustomActions" DllEntry="SetINSTALLFOLDER" Execute="immediate" Return="check" /> <InstallExecuteSequence> <Custom Action="SetINSTALLFOLDER" Before="LaunchConditions">NOT Installed<Custom> </InstallExecuteSequence>
and here is a snippet of the code in the custom action:
public class CustomActions { [CustomAction] public static ActionResult SetINSTALLFOLDER(Session session) { try { var installFolder = ... // defined here if (!string.IsNullOrEmpty(installFolder)) { session["INSTALLFOLDER"] = installFolder; session.Log("SetINSTALLFOLDER: set to '{0}'", session["INSTALLFOLDER"]); } return ActionResult.Success; } catch (Exception ex) { session.Log("SetINSTALLFOLDER exception: {0}", ex.Message); return ActionResult.Failure; } } }
The thing that I don't like is that it also overrides user overrides via msiexec command line arguments, but it wasn't an issue this time...