2011-06-22 28 views
1

我如果正在安装数据库的功能,设置为1的属性:WIX的ServiceControl条件

<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服务。我检查了日志,可以看到在运行cmp_SvcC和cmp_SvcC_Start之前DBFLAG被设置为1,但即使条件仅在DBFLAG = 0时仍然运行cmp_SvcC。

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

有没有人有任何想法,为什么会发生这种情况?

回答

2

它不这样工作。即使您通过属性间接地执行某项操作,也不能对某个组件进行条件限制。

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

+0

你可以扩展一下吗?我是wix的新手,我不太清楚你的意思。我是否将cmp_SvcC和cmp_SvcC_Start的添加到db功能? – knappster

+0

WiX不支持编辑FeatureComponents表。解决方案是使用Orca手动修改生成的MSI:http://msdn.microsoft.com/en-us/library/aa370557(VS.85).aspx。另一种解决方案是找到一个设置创作工具,它允许您修改此表。 –

+0

干杯,知道这一点后,我不得不现在开始他们的代码,因为构建过程需要自动化,并且无法继续编辑msi ... – knappster

1

另一种方法是在StartServices自定义操作本身上有条件。就像这样:

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

为了得到你想要使用,与逆戟鲸打开微星,看InstallExecuteSequence表和排序后的顺序号表什么序列号的线索。