views:

78

answers:

1

Right now, I can add an environmental variable on install with the Environment tag in WiX. Here's an example:

<Environment Id="LibPath" 
             Action="set" 
             Name="PATH" 
             Part="last"
             Separator=";" 
             System="yes" 
             Value="[INSTALLDIR]" />

However, sometimes, the environmental variable has already been installed on the client. In this case, that environmental variable must remain upon uninstall. However, if they did not have it already, we do want to remove it. After looking over the wix documentation for Environment, I'm not sure this is possible. It looks like I have two options:

  1. Leave the environmental variable polluting the name space, every time, on uninstall.
  2. Uninstall the variable, no matter what, even if I didn't install it.

Is this the case, or am I missing something? I've been looking, but it seems you either get the option to pollute, or remove always. Neither seems like the right solution.

+1  A: 

I haven't tried this but I think it should work:

  1. create a property (ENVEXISTS) and set it to 0
  2. detect if the env variable exists and set your propetry to 1
  3. do the set env variable twice using as condition the value of your property - once as remove at uninstall if it didn't existed and once as leave at uninstall if it existed
Gabriel
Sorry, my wix is somewhat hazy; how would I do a conditional?
Robert P
<Environment ....><![CDATA[Contition]]></Environment> should work ok
Gabriel
Won't that just do the conditional at compile time of the .msi?
Robert P
no, that is evaluated at install time.
Gabriel
Fantastic, I'll give it a shot!
Robert P