Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using if condition to compare variable values in WiX

I want to check whether the user has passed an argument for USERNAME for which the default value is local. I am trying to see if I I get a message if the value is local. The problem is in the following way. This doesn't work.

<Property Id="USERNAME" Value="local"/>
<?define uName = [USERNAME]?>

<?if $(var.uName) = local ?>
      <Condition Message="$(var.uName)">0</Condition>
<?endif?>

But, if I change the code to the following it will give the message.

<?define uName = local?>

<?if $(var.uName) = local ?>
      <Condition Message="$(var.uName)">0</Condition>
<?endif?>

And the following code assigns the value of the USERNAME property to the uName variable.

<Property Id="USERNAME" Value="local"/>
<?define uName = [USERNAME]?>
<Condition Message="$(var.uName)">0</Condition>

The above code prints 'local' in a message box.

I tried many scenarios and could locate where the problem is. When comparing variable values, which is assigned as,

<?define uName = [USERNAME]?>

Though the value is assigned to uName, we can't do the comparison. Am I doing anything wrong here? Or is there another way for this kind of problem?

like image 303
Isuru Gunawardana Avatar asked Mar 15 '13 09:03

Isuru Gunawardana


1 Answers

Could you do it like this without the variables?

<Property Id="USERNAME" Value="local"/>

<Condition Message="The username is local, please enter a username for the installation to proceed">USERNAME = "local"</Condition>

This would be correct if the user entered a username, then the installation would proceed but if the user did not then it would fail as the default is local.

I do wonder how the username is entered. Is this via the command line or from an input dialog?

If from a dialog - I would suggest having an error dialog rather than aborting the installation. I may be completely wrong but just giving you options.

Hope this helps...:)

EDIT:

To do what you want, simply add a condition to your component which has your service inside. Have two components:

<Component Id="ServiceOne" Guid='*' Directory="Directory">
 //All your service tags etc 
  <Condition><![CDATA[USERNAME = "local"]]></Condition>
</Component>

<Component Id="ServiceTwo" Guid='*' Directory="Directory">
 //All your service tags etc 
  <Condition><![CDATA[USERNAME <> "local"]]></Condition>
</Component>
like image 191
Natalie Carr Avatar answered Oct 21 '22 00:10

Natalie Carr