I have a property that is set to 1 if the database feature is being installed:
<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>
In another feature I check this DBFLAG to see if it is 0 or 1 and based upon this I want to start a service immediately or not:
<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>
However, it always runs the cmp_SvcC instead of the cmp_SvcC_Start service if the database feature is installed. I have checked the logs and can see that the DBFLAG is set to 1 before the cmp_SvcC and cmp_SvcC_Start are run but still the cmp_SvcC is run even though the condition is only when DBFLAG=0.
If I change the initial value of the DBFLAG to 1 then the cmp_SvcC_Start gets run.
Has anyone any idea as to why this is happening?
It doesn’t work this way. You cannot condition a component with a feature action, even if your are doing it indirectly through a property.
The correct approach is to share your component between all features which affect its installation. This is done through FeatureComponents table.