根据条件在 WiX 中设置属性 [英] Set a property in WiX based on a condition

查看:18
本文介绍了根据条件在 WiX 中设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我进行了注册表搜索(实际上是两个),因为我需要检查之前两次安装中的其中一个,然后将我的新文件安装到找到的之前安装的位置.>

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

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

<!— 查找第一个可能的产品的 UnInstall 密钥 --><!- GUID = {E928E024-DEFE-41A7-8469-D338212C4943} --><Property Id='PROD1'><RegistrySearch Id='PROD_REG1'类型='原始'根='HKLM'键='$(var.REGKEY_PROD1)'名称='安装位置'/></属性><!- 查找第二个可能的产品的 UnInstall 键--><!- GUID = {A40A9018-DB9D-4588-A591-F012600C6300} --><Property Id='PROD2'><RegistrySearch Id='PROD_REG2'类型='原始'根='HKLM'键='$(var.REGKEY_PROD2)'名称='安装位置'/></属性><!-- 如何将 INSTALL_HERE 属性设置为找到的InstallLocation"?--><!-- 定义目录结构--><Directory Id="TARGETDIR" Name="SourceDir"><目录 ID="INSTALL_HERE"><Directory Id="MAIN_DIRECTORY" Name="MyProduct"/><Directory Id="HELP_DIRECTORY" Name="Help"/></目录></目录>

解决方案

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

 <!-- 此处进行注册表搜索 1 --></属性><属性 ID="B"><!-- 此处进行注册表搜索 2 --></属性><SetProperty Id="A" After="AppSearch" Value="[B]">乙</SetProperty>

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

另见 Rob Mensching 的这个回答

This should be easy, but after several hours I’m coming up blank. ;(

I do a registry search (actually two), because I need to check for either of two previous installs and then install my new files to the location of the prior install that was found.

  • Only one of these prior installs will actually exist.

I then need to install my new files to the 'InstallLocation' of which 'PROD#' was found.

<!—  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>

解决方案

The following will set properties A and B to the result of two different registry searches. If the search for B was successfull, it overrides the value of A with the value of 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>

Note how the SetProperty element uses the value of B twice: once as Value="[B]" to override the value of A, and once as the condition text of the custom action. The After="AppSearch" ensures that the custom action is executed right after the registry searches.

See also this answer of Rob Mensching

这篇关于根据条件在 WiX 中设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆