失败条件wix

Failing condition wix

我试图在以下情况下跳过安装:

  1. Windows OS 类型是 = desktop OS
  2. if HKLM\SYSTEM\CurrentControlSet\Services\MyService MYKEY= myValue
  3. if REG HKLM\SYSTEM\CurrentControlSet\Services\MyService = DisplayName 存在 AND HKLM\SYSTEM\CurrentControlSet\Services\MyService MYKEY 不存在

安装时一切顺利,但安装时缺少我的功能。

我是不是放错了条件?

<Property Id="MYKEY" Secure="yes">
        <RegistrySearch Id="MyKey"
                             Root="HKLM"
                             Key="SYSTEM\CurrentControlSet\Services\MyService"
                             Name="mykey"
                             Type="raw" />
    </Property>
    <Property Id="MYSERVICE" Secure="yes">
        <RegistrySearch Id="MYSERVICE"
                        Root="HKLM"
                             Key="SYSTEM\CurrentControlSet\Services\MyService"
                             Name="DisplayName"
                             Type="raw" />
    </Property>
<Feature Id="MyFeature" Level="" Display="" Title="" Description="" AllowAdvertise="no" ConfigurableDirectory="INSTALLDIR">
   <MergeRef Id="MyFeature" Primary="yes"/>
   <Condition Level="0">((MsiNTProductType=1) OR 
   (MYKEY="MyValue") OR 
   (MYSERVICE="MyService" AND MYKEY=""))</Condition>
   </Condition>
</Feature>

注意:以下内容尚未经过广泛测试 - 条件因难以正确而臭名昭著。测试条件需要真实世界的测试。更多链接:

  • (复杂条件的例子)
  • How to add a WiX custom action that happens only on uninstall (via MSI)?

当这三个“子”条件中的任何一个为真时,您想实现什么?

  1. 中止设置: 中止整个设置? (LaunchConditions)
  2. 配置功能:阻止或启用特定功能的安装? (Feature conditions)

这个区别显然是至关重要的 - 我们必须知道才能回答。您的 WiX 源代码片段当前显示用作特征条件的条件。我感觉这不是你想要的。


LaunchConditions:如果这些条件之一为真,为了中止整个设置,您可以尝试使用 LaunchCondition 条目。您可以将它们分成三个不同的条目,而不是创建一个复杂的条件,每个条目检查是否应该中止设置 - 每个条目都有不同的特定原因。我建议您在 WiX 源文件中的 Package 元素之后添加这些 LaunchCondition 条目:

<Condition Message="Aborting setup: Server OS required for installation.">Installed OR MsiNTProductType=1</Condition>
<Condition Message="Aborting setup: State reason for abortion.">Installed OR MYKEY="MyValue"</Condition>
<Condition Message="Aborting setup: State reason for abortion.">Installed OR (MYSERVICE="MyService" AND MYKEY="")</Condition>

这些条目将进入已编译 MSI 文件的 LaunchCondition table

LaunchConditions 必须始终评估为 true 才能使安装程序能够安装/运行.

因此,上述条件的 Installed 部分用于确保安装后条件始终为真 - 因此您不会遇到安装程序不允许自身被卸载或已修复,因为未满足启动条件。条件:Installed - 除了 fresh installmajor upgrades.

之外始终为真

注意:我不确定启动条件是否会在管理安装期间造成问题。我不认为他们这样做(管理安装具有自己的安装顺序)。我明天会测试和验证。当管理安装为 运行.

时,添加 OR ACTION="ADMIN" 应该使任何框的启动条件为真

Feature Conditions:如果您不想中止安装,而是想根据评估控制功能安装状态这些条件,您需要使用特征条件概念而不是启动条件概念。

当您在 WiX 源中将 Feature level 设置为 0 时,此功能未显示在设置 GUI 中,它是 默认情况下也不会安装功能条件 可以改变这一点,并设置功能在条件评估为真时安装。

您也可以反过来将功能级别设置为默认 1(这应该会安装该功能),然后使用功能条件将其功能级别设置为 0 - 如果您不希望已安装功能 - 当条件为真时。

此处“快速模型”下有一些进一步的详细信息:

在下面的 WiX 片段中,我们设置了默认安装的功能 (Level="1"),然后我们使用 功能条件 将功能设置为不安装,如果其关联条件的计算结果为真(这是一个多部分条件)。因此,一旦条件评估为真,我们将分配功能 Level="0"(这意味着不安装功能并将其从设置 GUI 中隐藏):

<Feature Id="MyFeature" Level="1"> <!--Default to install feature-->

  <Condition Level="0"> <!--Do not install feature if condition is true-->
    ((MsiNTProductType=1) OR (MYKEY="MyValue") OR (MYSERVICE="MyService" AND MYKEY="") AND (NOT ACTION="ADMIN"))
  </Condition>

</Feature>

AND (NOT ACTION="ADMIN") 部分是强制在管理安装中安装该功能。如果在管理安装模式下设置为 运行,它会有效地关闭其他条件评估为真 - 这将导致在管理安装期间不安装该功能。这最后一部分我明天必须测试。

UPDATE: Testing indicates that any feature set to Level=0 as default will not be extracted during an administrative install at all, regardless of any feature conditions setting the feature to install. I guess the tentative conclusion is to not set any features to Level=0, but set Level=1 and then set them to Level=0 with a feature condition that evaluates to true. This way the feature may be hidden in a regular installation, but all features - with associated files - are extracted during admin installation. The AND (NOT ACTION="ADMIN") part of the condition appears to not be needed. Leaving the sample above as it is for now.


链接:

  • How to execute custom action only in install (not uninstall)
  • How to add new framework version in Installment Requirement page of InstallShield?