ArkTekniK
ArkTekniK

Reputation: 346

Dynamically set install dir in WiX from environment variable

I'm new to MSI development (with WiX or otherwise) and I'm trying to read the value of an environment variable and use it as the installation directory. My msi is gui-less too and giving the user the option to override the path is not permitted.

I can successfully read the var with:

<SetProperty 
    Id="TARGETINSTALLDIR" 
    Value="[%MY_ENV_VAR]\My\Install\Path" 
    After="LaunchConditions" 
    Sequence="first"  />

I can see in the msi logs the correct path retrieved.

I have tried the following to set the returned path:

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="APPLICATIONROOTDIRECTORY" Name="[TARGETINSTALLDIR]"/>
</Directory>

Also,

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="APPLICATIONROOTDIRECTORY" Name="TARGETINSTALLDIR"/>
</Directory>

Failing that, I also tried to read the directory path within the ROOT Directory as shown below

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ROOT" Name="[%MY_ENV_VAR]">
      <Directory Id="My" Name="My">
        <Directory Id="Install" Name="Install">
          <Directory Id="APPLICATIONROOTDIRECTORY" Name="Path"/>
        </Directory>
      </Directory>  
    </Directory>
</Directory>

Is there some syntax I'm missing or am I fundamentally misunderstanding how this should be done?

Upvotes: 3

Views: 3738

Answers (1)

ArkTekniK
ArkTekniK

Reputation: 346

Right, I figured it out.

Rather than using a SetProperty Element, I should have used a SetDirectory Element. The markup is simple;

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="APPLICATIONROOTDIRECTORY"/>
</Directory>
<SetDirectory Id="APPLICATIONROOTDIRECTORY" Value="[%MY_ENV_VAR]\My\Install\Path" Sequence="first"  />

Hopefully this helps someone else out.

Upvotes: 7

Related Questions