Search code examples
wixwix3

WiX optional Section Content


I am trying to write a simple windows installer that has to write some fields in a .ini file if a feature is enabled. On the lower level, this is if a specific property is set from a checkbox.

I have been googling for days, but neither the internet nor the docs seem to be of help. Can anyone point me in the right direction regarding having optional fields in a section?


Solution

  • After many failed attempts, I decided to define a feature with a condition inside:

    <Feature Id="MyFeature" Title="My Feature" Level="1">
        <Condition Level="1">MYCONDITION</Condition>
            <Component Id="MyComponent" Guid="..." KeyPath="yes" Directory="INSTALLDIR">
                 <Condition>MYCONDITION</Condition>
                 <IniFile ... Property="OTHERPROPERTY">
            </Component>
    </Feature>
    

    The Property MYCONDITION gets set by a Checkbox somewhere else in a Dialog:

    <Control Id="MyCheckBox" Type="CheckBox" [...] Property="MYCONDITION" CheckBoxValue="FALSE" />
    

    The Property OTHERPROPERTY gets set in the respective Control fields. For this, simply defining it in those fields is enough. This way, you can read the values of those fields if MYCONDITION was set or ignore them if not.


    To recap: if you want to install something that doesn't absolutely have to be there (aka a Feature), but the user has the freedom of choosing, you can bind the feature on a certain condition that gets set somewhere else. To me, the "somewhere" was a CheckBox and the particular condition was a Property.

    Disclaimer

    I must admit that I am fairly inexperienced with Windows installers and this solution may not be sane or break some conventions. However, it does the trick for me. I must mention I did not try the approach of setting the registry keys mentioned in another answer, as I was unsure as to whether those keys would persist after the potential de-installation of the software.