【问题标题】:WIX ServiceControl ConditionWIX 服务控制条件
【发布时间】:2011-06-22 10:57:07
【问题描述】:

如果正在安装数据库功能,我有一个属性设置为 1:

<Property Id="DBFLAG" Value="0" />
<CustomAction Id="DbCheck" Return="check" Execute="immediate" Property="DBFLAG" Value="1" />
<InstallExecuteSequence>
        <Custom Action="DbCheck" After="CostFinalize"><![CDATA[&ft_db=3]]></Custom>
</InstallExecuteSequence>

在另一个功能中,我检查此 DBFLAG 以查看它是 0 还是 1,并基于此我想立即启动服务:

<Component Id="cmp_Svc" Guid="99481212-F2E0-4B6E-934D-0994815C31ED">
            <File Id="FILE01" Source="$(var.Service.TargetDir)\Service.exe" KeyPath="yes" />

            <ServiceInstall Id="Svc" Name="My Service" Type="ownProcess" Account="[WIX_ACCOUNT_LOCALSYSTEM]" Description="My Service." DisplayName="My Service" ErrorControl="normal" Interactive="no" Start="auto" Vital="no" />
</Component>
<Component Id="cmp_SvcC_Start" Guid="2ED5DBC7-BD42-4D46-AB18-E82DB0E317AD">
            <Condition>DBFLAG=1</Condition>
            <ServiceControl Id="SvcC_Start" Name="My Service"  Remove="uninstall" Stop="both" Wait="yes" Start="install" />
</Component>

<Component Id="cmp_SvcC" Guid="5769A35B-FD61-45D4-8113-40FB762B79C6">
            <Condition>DBFLAG=0</Condition>
            <ServiceControl Id="SvcC" Name="My Service"  Remove="uninstall" Stop="both" Wait="yes" />
</Component>

但是,如果安装了数据库功能,它总是运行 cmp_SvcC 而不是 cmp_SvcC_Start 服务。我检查了日志,可以看到 DBFLAG 在 cmp_SvcC 和 cmp_SvcC_Start 运行之前设置为 1,但 cmp_SvcC 仍然运行,即使条件仅在 DBFLAG=0 时运行。

如果我将 DBFLAG 的初始值更改为 1,那么 cmp_SvcC_Start 就会运行。

有人知道为什么会这样吗?

【问题讨论】:

    标签: installation wix wix3.5


    【解决方案1】:

    这种方式是行不通的。即使您是通过属性间接执行此操作,您也无法使用功能操作来调节组件。

    正确的方法是在影响其安装的所有功能之间共享您的组件。这是通过FeatureComponents table 完成的。

    【讨论】:

    • 你能扩展一下吗?我是 wix 新手,不太清楚你的意思。我是否将 cmp_SvcC 和 cmp_SvcC_Start 的 添加到 db 功能?
    • WiX 不支持编辑 FeatureComponents 表。一种解决方案是使用 Orca 手动修改生成的 MSI:msdn.microsoft.com/en-us/library/aa370557(VS.85).aspx。另一种解决方案是找到一个允许您修改此表的设置创作工具。
    • 干杯,在知道这一点后,我现在不得不从代码开始它们,因为构建过程需要自动化并且之后无法编辑 msi...
    • @Cosmin,这不是真的:WiX 支持 FeatureComponents 表,其中包含 Feature/FeatureRef 下的 Component/ComponentRef/ComponentGroupRef。 @knappster,请参阅 joyofsetup.com/2008/04/09/…joyofsetup.com/2007/05/30/feature-conditions-and-ui 了解为什么您的原始技术不起作用。
    • @BobArnson 我们无法更新 FeatureComponents 表。原因是两列都是主键。我们只需要删除并创建新行 ref:faqshop.com/scripting/default.htm?http://www.faqshop.com/…
    【解决方案2】:

    另一种方法是对 StartServices 自定义操作本身设置条件。像这样:

    <InstallExecuteSequence>
    <StartServices Sequence="5900">
        <![CDATA[VersionNT AND DBFLAG="1"]]>
    </StartServices>
    </InstallExecuteSequence>
    

    为了知道您想使用什么序列号,请使用 Orca 打开您的 msi,查看 InstallExecuteSequence 表并将该表排序到序列号之后。

    【讨论】:

    • 另请注意,您不必设置Sequence 数字 - MSI/WIX 默认设置一个,通常为 5900。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多