22
votes

I'm creating a program which is being installed by Wix, using VS 2010 and I've already got the product.wxs ready.

In my wxs file, I've got directory definitions which looks like this:

<SetDirectory Id="INSTALLFOLDER" Value="[WindowsVolume]Myapp" />
<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="INSTALLFOLDER" Name="Myapp">
    <Directory Id="Myapp_Installer_Dir" Name="Myapp">
          <Directory Id="BIN" Name="Bin" />
          <Directory Id="ICONS" Name="Icons" />
    </Directory>
  </Directory>
</Directory>

And then I got these file installation definitions:

<DirectoryRef Id="Myapp_Installer_Dir">
  <Component Id="INSTALLER_Myapp" Guid="{94F18477-8562-4004-BC6F-5629CC19E4CB}" >
    <File Source="$(var.Myapp.TargetPath)" KeyPath="yes"/>
  </Component>
</DirectoryRef>

<DirectoryRef Id="BIN">
  <Component Id="INSTALLER_Data" Guid="{545FB5DD-8A52-44D7-898E-7316E70A93F5}" >
    <File Source="$(var.Data.TargetPath)" KeyPath="yes"/>
  </Component>
    ...

And it continues in that manner. The files for the "ICONS" directory are defined as well.

I am also using the WixUI_InstallDir dialog set and I got these lines present as well:

<Property Id="WIXUI_INSTALLDIR" Value="Myapp_Installer_Dir" />
<UIRef Id="WixUI_InstallDir" />

The problem is when the user installs the program and changes the value of the installation folder, the files of the "Bin" and "Icons" are installed to their correct path, but the Myapp target is installed to a fix location which was defined at the start as the default installation path.

Why do only the bin and icon files installed to the correct folder the user wanted, but the myapp target does not?

3

3 Answers

41
votes

I have finally figured out the problem. After searching for a while, I came across this document:

WixUI_InstallDir Dialog Set

The relevant part: "The directory ID must be all uppercase characters because it must be passed from the UI to the execute sequence to take effect."

And as you can see in my code: "Myapp_Installer_Dir" does not meet this criteria.

After changing it to "MYAPPINSTALLERDIR", everything worked.

3
votes

I'm not quite sure, but this is what I think has happened.

When you author a SetDirectory element, you basically add a custom action which sets a directory to the MSI database. As long as you do not specify the sequence it is executed in, it defaults to both, which means execute in both InstallUISequence and InstallExecuteSequence.

Now, when a user changes the installation directory in the wizard, this happens in the UI sequence. Obviously, when the installation enters the execute sequence, the value of INSTALLFOLDER is set to [WindowsVolume]Myapp as it was instructed.

So, you have to rework this somehow. Keep in mind the silent installation as well - there's only execute sequence there.

UPDATE instead of what you have, try something like this:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="WindowsVolume">
    <Directory Id="INSTALLFOLDER" Name="Myapp">
      <Directory Id="BIN" Name="Bin" />
      <Directory Id="ICONS" Name="Icons" />
    </Directory>
  </Directory>
</Directory>

And let the user optionally change the INSTALLFOLDER as you do now.

0
votes

Additionally to the pitfall with capital letters there is also an other one:

You have to mark the ID of the changeable directory as secure. (At least when the setup runs with admin rights.)

Related to Yonatan's answer with the directory ID MYAPPINSTALLERDIR you have to add this:

<Property Id="MYAPPINSTALLERDIR" Secure="yes" />

Related to the example WixUI_InstallDir in the WiX documentation you have to add this:

<Property Id="TESTFILEPRODUCTDIR" Secure="yes" />

Unfortunately this important fact is not mentioned in the WiX example.