2

I'm trying to create an msi installer that will install the application to the console session's local app data directory, even when the session that runs the msi is the system session (when deploying via GPO).
For that, I'm creating a custom action that extracts the 'right' local app data directory (this code works, no issues there).
The custom action will set the value of a property called 'INSTALLDIR'.
This is the relevant code from the wxs:

<Property Id="INSTALLDIR" Value="C:\Users\default\AppData\Local\" />
<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="INSTALLDIR">
        <Directory Id="APPLICATIONFOLDER" Name="MyApp">
        ...

<Binary Id="MyCA" SourceFile="My.CustomActions.CA.dll"/>
<CustomAction Id="MyCASetLocalAppData" Impersonate="no" BinaryKey="MyCA" DllEntry="SetLocalAppData" Return="check" />
...

<InstallExecuteSequence>
    <Custom Action="MyCASetLocalAppData" Before="CostFinalize">Not Installed OR UPGRADINGPRODUCTCODE</Custom>

In the install log, I can see the INSTALLDIR's value change from the initial value to the right value from the custom action, but later on in the log, the INSTALLDIR's value is the default value again.

It seems like I need to call the MyCASetLocalAppData multiple times...

How can I fix this?

Thanks!

1 Answer 1

2

I know that the docs say to schedule before CostFinalize, but that might be too late. Try changing it to After="CostInitialize" (which is when WiX's SetDirectory element schedules it).

Sign up to request clarification or add additional context in comments.

2 Comments

I found out the solution a couple of weeks ago - the solution is what you suggested, you should have come earlier, save me some time:) Marking this as the answer for future reference for other people
Another alternative is to set a property of the exact same Id (case sensitive) as the directory's Id to the desired path BEFORE CostInitialize (which is actually how the "built in" directories are set), because during costing if there's a property that shares the directory's Id then that property's value is automatically used (ignoring that directory's parent). Costing also effectively creates properties for all of the directories with their paths (which you can use after CostFinalize in your code).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.