3

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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.