Wix - Setting Install Folder correctly

2019-01-14 16:50发布

问题:

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 and 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 I'm facing is that 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 location, but the Myapp target is installed to a fix location that was defined in the start.

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

回答1:

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.



回答2:

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.