根据条件在WiX中设置属性

Zer*_*ren 14 conditional wix properties

应该很容易,但几个小时后我就空白了.(

我做了一个注册表搜索(实际上是两个),因为我需要检查前两个安装中的任何一个,然后将我的新文件安装到找到的先前安装的位置.

  • 这些先前安装中只有一个实际存在.

然后我需要将我的新文件安装到找到'PROD#'的'InstallLocation'.

<!—  Look for the UnInstall key of the 1st possible product  -->
<!—  GUID = {E928E024-DEFE-41A7-8469-D338212C4943}           -->
<Property Id='PROD1'>
    <RegistrySearch Id='PROD_REG1'
                    Type='raw'
                    Root='HKLM'
                    Key='$(var.REGKEY_PROD1)'
                    Name='InstallLocation' />
</Property>

<!—  Look for the UnInstall key of the 2nd possible product  -->
<!—  GUID = {A40A9018-DB9D-4588-A591-F012600C6300}           -->
<Property Id='PROD2'>
  <RegistrySearch Id='PROD_REG2'
                  Type='raw'
                  Root='HKLM'
                  Key='$(var.REGKEY_PROD2)'
                  Name='InstallLocation' />
    </Property>

<!--  How do I set INSTALL_HERE Property to whichever ‘InstallLocation’ was found?  -->

<!--  Define the directory structure  -->
<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="INSTALL_HERE">
        <Directory Id="MAIN_DIRECTORY" Name="MyProduct"/>
        <Directory Id="HELP_DIRECTORY" Name="Help"/>
    </Directory>
</Directory>
Run Code Online (Sandbox Code Playgroud)

Wim*_*nen 24

以下内容将属性A和B设置为两个不同注册表搜索的结果.如果搜索B成功,则它将覆盖A的值,其值为B.

  <Property Id="A">
     <!-- registry search 1 here -->
  </Property>

  <Property Id="B">
     <!-- registry search 2 here -->
  </Property>

  <SetProperty Id="A" After="AppSearch" Value="[B]">
     B
  </SetProperty>
Run Code Online (Sandbox Code Playgroud)

请注意SetProperty元素如何使用B的值两次:一次Value="[B]"用于覆盖A的值,一次用作自定义操作的条件文本.在After="AppSearch"确保自定义操作注册表搜索后立即执行.

另见Rob Mensching的答案