Using project.ControlPanelInfo.InstallLocation

Dec 11, 2015 at 10:15 AM
I try to use field Project.InstallLocation for store instalattion location for further major upgrades. I use it next way
//resolve value of INSTALLDIR and set it to ARPINSTALLLOCATION
project.ControlPanelInfo.InstallLocation = "[INSTALLDIR]";

//on upgrade set value of install location to INSTALLDIR
project.AddProperty(
            new RegValueProperty("INSTALLDIR", Microsoft.Win32.RegistryHive.LocalMachine,
                @"Software\Microsoft\Windows\CurrentVersion\Uninstall\[UPGRADEFOUND]", "InstallLocation"));
It works fine for first instalation (value of INSTALLDIR store to registry). And it works fine for first upgrade (value read correctly from registry). But after upgrade value of InstallLocation in registry is empty, so all next upgrades will fail.
Dec 11, 2015 at 10:19 AM
Code above generate next wix markup

//action that resolve value of INSTALLDIR and set it to ARPINSTALLLOCATION
<CustomAction Id="Set_ARPINSTALLLOCATION" Property="ARPINSTALLLOCATION" Value="[INSTALLDIR]" />

//in sequence action Set_ARPINSTALLLOCATION execute before AppSearch only when (NOT Installed)
<InstallExecuteSequence>
<Custom Action="WixSharp_InitRuntime_Action" Before="AppSearch"> (1) </Custom>
<Custom Action="Set_ARPINSTALLLOCATION" After="WixSharp_InitRuntime_Action"> (NOT Installed) </Custom>
</InstallExecuteSequence>
Dec 11, 2015 at 10:34 AM
From aistallation log

Action ended 11:45:23: WixSharp_InitRuntime_Action. Return value 1.
MSI (s) (9C:7C) [11:45:23:751]: Doing action: Set_ARPINSTALLLOCATION
MSI (s) (9C:7C) [11:45:23:751]: Note: 1: 2205 2: 3: ActionText
Action start 11:45:23: Set_ARPINSTALLLOCATION.
MSI (s) (9C:7C) [11:45:23:753]: PROPERTY CHANGE: Adding ARPINSTALLLOCATION property. Its value is 'D:\inetpub\wwwroot\Test'.
Action ended 11:45:23: Set_ARPINSTALLLOCATION. Return value 1.
MSI (s) (9C:7C) [11:45:23:754]: Doing action: AppSearch

From upgrade lo

Action ended 11:46:58: WixSharp_InitRuntime_Action. Return value 1.
MSI (s) (9C:44) [11:46:58:542]: Doing action: Set_ARPINSTALLLOCATION
MSI (s) (9C:44) [11:46:58:542]: Note: 1: 2205 2: 3: ActionText
Action start 11:46:58: Set_ARPINSTALLLOCATION.
Action ended 11:46:58: Set_ARPINSTALLLOCATION. Return value 1.
MSI (s) (9C:44) [11:46:58:546]: Doing action: AppSearch
...
Action ended 11:47:18: WixSharp_InitRuntime_Action. Return value 1.
MSI (s) (9C:58) [11:47:18:448]: Skipping action: Set_ARPINSTALLLOCATION (condition is false)
MSI (s) (9C:58) [11:47:18:448]: Doing action: AppSearch
Dec 11, 2015 at 11:01 AM
When I add custom action to set value of ARPINSTALLLOCATION (it execute afte InstallValidate) instead using project.ControlPanelInfo.InstallLocation = "[INSTALLDIR]"; all works fine.

new SetPropertyAction("ARPINSTALLLOCATION", "[INSTALLDIR]", Return.check, When.After, Step.InstallValidate, Condition.NOT_Installed)

Maybe it's too early execute Set ARPINSTALLLOCATION before AppSearch?
Dec 11, 2015 at 12:05 PM
As I can see the problem is in the fact that the registry entry is removed on uninstall triggered by update. Have a look at "Persisting AppInfo" sample it shows how to prevent regvalue from removal (both native and managed approach).

The fragment from the sample:
new RegValue(RegistryHive.LocalMachine, @"Software\My Company\My Product", "InstallationDirectory", "[INSTALLDIR]") 
{
    AttributesDefinition = "Component:Permanent=yes" 
}