I know this is a common issue with WiX and I am aware that a solution for this might be easy, but I am stuck and none of the topics I could find helped me so here I go.
I'm using WiX 3.11 in Visual Studio with a very simple UI dialog sequence, which is taken from the wix documentation examples:
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UI>
<UIRef Id="WixUI_InstallDir"/>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2"> 1 </Publish>
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2"> 1 </Publish>
</UI>
Where INSTALLFOLDER is defined somewhere else in my directories definition.
As you can see, this is pretty straightforward:
- Welcome
- Choose a directory
- End the installation
Now, I would like to modify this set up to skip the InstallDir dialog when the .msi is upgrading, and do the upgrade directly in the existing install folder.
I have written a registry value in HKCU which stores the install path, and used a property to retrieve it when installing. I tried to use conditions to create a different dialog sequence in the UI and set the install folder according to my property, but it ended up with errors when running the .msi file.
Here is what it looks like now:
<Product ...Some stuff here ... >
<Property Id="ALREADYINSTALLED">
<RegistrySearch Id="InstallPath"
Key="Software\$(var.MainDir)\$(var.SecondaryDir)"
Name="InstallFolder"
Root="HKCU"
Type="directory"
Win64="$(var.Win64)"/>
</Property>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UI>
<UIRef Id="WixUI_InstallDir"/>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2"> <![CDATA[NOT ALREADYINSTALLED]]> </Publish>
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2"> <![CDATA[NOT ALREADYINSTALLED]]> </Publish>
/!\ Interesting part here /!\
<Publish Dialog="WelcomeDlg" Control="Next" Event="SetTargetPath" Value="[ALREADYINSTALLED]" Order="2"> <![CDATA[ALREADYINSTALLED]]> </Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="2"> <![CDATA[ALREADYINSTALLED]]> </Publish>
</UI>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="SAFEFOLDER" Name="$(var.MainDir)">
<Directory Id="INSTALLFOLDER" Name="$(var.SecondaryDir)" />
</Directory>
</Directory>
</Directory>
</Fragment>
<Component ... Some stuff here ... >
<RegistryValue Root="HKCU"
Key="Software\$(var.MainDir)\$(var.SecondaryDir)"
Name="InstallFolder"
Type="string"
Value="[INSTALLFOLDER]"
KeyPath="yes" />
... Some other stuff here ...
</Component>
My conditions seems to be working fine, but I couldn't pass the install folder using the property.
I feel I'm missing something simple, but I can't figure out what.
Can anybody help me please?