Wix: show custom dialog if previous version found

2019-02-17 17:01发布

问题:

I want to customize my installer to show custom dialog when previous version is already installed: after Welcome dialog user should see a custom dialog OldVersionDlg with information that previous version was found and will be uninstalled automatically.

But for some reason property set by UpgradeVersion element always null when I check it in condition in UI/Publish Dialog.

Here are essential code snippets.

Product.wxs:

<Product Id="*" Version="$(var.Version)" UpgradeCode="$(var.ProductId)"
         Language="1033" Name="$(var.ProductFullName)" Manufacturer="$(var.Manufacturer)">
  <Package Description="$(var.ProductDescription)" InstallerVersion="200" Compressed="yes" 
           Manufacturer="$(var.Manufacturer)" />

  <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
  <Upgrade Id="$(var.ProductId)">
    <UpgradeVersion Minimum="1.0.0.0" Maximum="$(var.Version)"
                    Property="PREVIOUSVERSIONSINSTALLED"
                    IncludeMinimum="yes" IncludeMaximum="no" />
  </Upgrade>

  <InstallExecuteSequence>
    <RemoveExistingProducts Before="InstallInitialize" />
  </InstallExecuteSequence>
</Product>

WixUI_Wizard.wxs:

<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="OldVersionDlg">PREVIOUSVERSIONSINSTALLED</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg">NOT Installed</Publish>

The button Next doesn't work. I've checked in logs that PREVIOUSVERSIONSINSTALLED is set after FindRelatedProducts. If I use it in conditions in Product.wxs then everything is OK. But in UI configuration it is always null.

Thanks for any help.

回答1:

The problem was caused by the second line in WixUI_Wizard.wxs. For some reason WiX always uses it. So, to implement checking of previous version we need to exclude PREVIOUSVERSIONSINSTALLED from the second condition:

<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="OldVersionDlg">PREVIOUSVERSIONSINSTALLED</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg">NOT Installed AND NOT PREVIOUSVERSIONSINSTALLED</Publish>


标签: wix wix3.5