Conditionally set single WiX Property to different values

14,082

Solution 1

SetProperty now supports the Action attribute to let you specify custom action ids when you want to have multiple SetProperty elements for the same property with different conditions.

Solution 2

The accepted answer is not correct in needing to convert to writing out in full the custom action and sequencing (no longer?).

As per documentation for WiX 3, SetProperty Element

Without setting SetProperty\@Action

<SetProperty Id="OUTPORT" Before="InstallFiles" Value="80"><![CDATA[SSL=0]]></SetProperty>
<SetProperty Id="OUTPORT"  Before="InstallFiles" Value="443"><![CDATA[SSL=1]]></SetProperty>

Duplicate symbol 'CustomAction:SetInstallFiles' found

Action. String. By default, the action is "Set" + Id attribute's value. This optional attribute can override the action name in the case where multiple SetProperty elements target the same Id (probably with mutually exclusive conditions).

The following works without having to change to writing out custom actions.

<SetProperty Action="SetInstallFiles0" Id="OUTPORT" Before="InstallFiles" Value="80"><![CDATA[SSL=0]]></SetProperty>
<SetProperty Action="SetInstallFiles1" Id="OUTPORT" Before="InstallFiles" Value="443"><![CDATA[SSL=1]]></SetProperty>

It works in WiX 3.7, and I am not sure about which first version it is available from.

Share:
14,082
A C S
Author by

A C S

Director of Engineering @ Featurespace: Release Management Programme Management Continuous Improvement of people and processes Product Management MSc in Psychological Research Methods web: Irishperson in Exile twitter:djryan facebook: Damien Ryan linkedin: Damien Ryan

Updated on June 14, 2022

Comments

  • A C S
    A C S almost 2 years

    I have an installer that deploys a website as either a SSL or non-SSL IIS site depending on whether a property is set or not. I've been asked to add the option to set the port, which isn't a problem, but I'd like to set the port to the default values (80 or 443) if the value isn't set.

    I tried something like:

        <SetProperty Id="OUTPORT" Before="InstallFiles" Value="80"><![CDATA[SSL=0]]></SetProperty>
        <SetProperty Id="OUTPORT"  Before="InstallFiles" Value="443"><![CDATA[SSL=1]]></SetProperty>
    

    But, obviously, WiX complains about the custom action having the duplicate ID SetOUTPORT.

    Am I jumping down another WiX-shaped rabbit hole here?

  • A C S
    A C S almost 13 years
    Perfect @Bob. When I first saw "CustomAction" I thought I was going to have to do the whole lot in managed code.
  • Greg Domjan
    Greg Domjan about 11 years
    This doesn't appear to be valid (?any longer) wix.sourceforge.net/manual-wix3/wix_xsd_setproperty.htm
  • Bob Arnson
    Bob Arnson about 11 years
    Yes, SetProperty and SetDirectory were enhanced to support this scenario.
  • Yan Sklyarenko
    Yan Sklyarenko about 11 years
    @Greg, I think it makes sense to edit original answer with this info for consistency.