How can I use an update condition to set variables in Wix?

偶尔善良 提交于 2019-12-11 02:02:29

问题


We are using Wix V3.11 to build an msi setup for our C#-Application. We have a 32 Bit and an 64 Bit build for each version:

The preallocated installation path for the 32 Bit build is: 'C:\Program Files (x86)'.

The preallocated installation path for the 64 Bit setup is: 'C:\Program Files'.

We use the following declaration to set the paths:

<?define bitness = $(var.Platform) ?>
<?if $(var.Platform) = "x86" ?>
<?define ProgramFilesPath = ProgramFilesFolder?>
    <?define Win64 = no?>
<?else?>
<?define ProgramFilesPath = ProgramFiles64Folder?>
    <?define Win64 = yes?>
<?endif?>

Using the variable here:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="$(var.ProgramFilesPath)" Name="$(var.ProgramFilesPath)">

        [... more folder ...]

  </Directory>
</Directory>

The Problem: When the consumer changes the path for the first installation to e.g. 'C:/MyFolder' and executes an updade, then the msi setup moves the software to 'C:\Program Files (x86)' or 'C:\Program Files'.

Question: How can I keep the custom installation path 'C:/MyFolder' of the first installation on an update? Perhaps is there any 'update' condition I can use? My imagination:

<?define bitness = $(var.Platform) ?>
<?if UPDATE ?> <!-- here -->
    <?if $(var.Platform) = "x86" ?>
    <?define ProgramFilesPath = ProgramFilesFolder?>
        <?define Win64 = no?>
    <?else?>
    <?define ProgramFilesPath = ProgramFiles64Folder?>
        <?define Win64 = yes?>
    <?endif?>
<?endif?>

回答1:


Let's assume that by "update" you mean a major upgrade because it would be extremely strange if a patch or minor update moved all the files from one location to another.

If you are using the usual WiX property name, then the directory chosen by the user will be INSTALLFOLDER, although it's not clear if you are using that or TARGETDIR. Basically you can store the user's final choice in a registry item (or use the WiX "remember property" pattern). On a major upgrade you can retrieve that property and set your INSTALLFOLDER value to that directory on condition that WIX_UPGRADE_DETECTED is set (the default property id used in the major upgrade element). Presumably you will also suppress the browse dialog that allows the user to choose the folder.

Having said that:

  1. It's not clear why you don't want the user to install the major upgrade to a new location if they want to, if the app continues to work.

  2. Those default folders aren't really preallocated - they are just the standard defaults. They are the recommended locations so it might be better to disallow changing them because of the opportunities for unexpected behavior. For example, attempting to install the 32-bit MSI to the native program files folder on an x64 system will result in redirection to the program files (x86) location, which may surprise the user.



来源:https://stackoverflow.com/questions/47506733/how-can-i-use-an-update-condition-to-set-variables-in-wix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!