26

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?

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

3 Answers3

42

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.

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • 1
    If the letters case is correct, and it still doesn't work as expected, then it is worth revising the `SetDirectory` action to specify `Sequence` for it as suggested by Yan (setting `first` did the trick in my case). And in general the issue can be traced down with verbose logging... – AntonK Jan 25 '18 at 00:45
4

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.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • Do you have any suggestions on this work around and how can I do it? – CodeMonkey Oct 14 '13 at 11:31
  • If it's not a strict requirement for your project, I would avoid `SetDirectory` part at all. Just let the default option stay (I mean ProgramFilesFolder). And let the user choose just one folder location, other paths should be built relative to that one. – Yan Sklyarenko Oct 14 '13 at 11:48
  • This folder I've set is required to be the default installation folder.. I can't change it – CodeMonkey Oct 14 '13 at 11:56
  • Didn't work... First of all the default location has been changed according to what you've added and it now had a "WindowsVolume" folder before the "Myapp" folder which remained the last folder of the default location. (C:\Myapp\WidnowsVolume\Myapp instead of the same path without the "WindowsVolume"). Also, when I changed the install location to C:\Myapp\aaa, the Bin and Icons folder were installed there but the myApp targetpath was installed to the default location I wrote with the "WindowsVolume" folder, ignoring the "aaa" folder I entered. – CodeMonkey Oct 14 '13 at 13:10
  • So, let me clarify: you need to install into `C:\MyApp\(bin|icons)` in case a user goes with the default option, and into `[INSTALLFOLDER]\(bin|icons)` in case he changes the target location, right? If that's the case, I've updated the sample. Try playing with it in case it doesn't work out of the box. – Yan Sklyarenko Oct 14 '13 at 13:47
  • It needs to be at C:\MyApp\Myapp\(bin|icons) but it's the same. Did you actually mean WindowsVolume as Id? Since it doesn't compile because this ID already exists – CodeMonkey Oct 14 '13 at 15:24
  • I have managed to find the problem. Check out the answer I've added – CodeMonkey Oct 15 '13 at 13:29
0

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.

Beauty
  • 865
  • 11
  • 14