1

I'm writing a Wix installer and one of the requirements is that the user can specify a target directory. Now, I'm very unfamiliar with Wix and so am trying to get my head around how it works. Ordinarily, a user specifying an installation directory seems fairly simple, so this is what I've done:

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="PlatformProgramFilesFolder">
            <Directory Id="foo" Name ="foo">
                <Directory Id="INSTALLFOLDER" Name="bar" />
            </Directory>
        </Directory>
    </Directory>
</Fragment>

So, if the user on the command line specifies a INSTALLFOLDER it will use that rather than the default install path. However, they specifically want to use the name TARGETDIR as the variable for specifying the target install directory as below:

msiexec /i foobar.msi TARGETDIR=C:\foo\bar\

Now TARGETDIR is predefined, so you can't just use it as a replacement for INSTALLFOLDER. So is there a way that I can make this work or am I just missing something very stupidly simple?

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
The Welder
  • 916
  • 6
  • 24
  • Have a look at this [thread](https://stackoverflow.com/questions/11003336/what-is-the-usage-of-targetdir-and-installdir-in-wix) – Pavel Anikhouski Jul 08 '19 at 11:05
  • Will have a look later. Lobbing you some links for now: [1](https://stackoverflow.com/questions/1641094/in-wix-files-what-does-name-sourcedir-refer-to), [2](https://stackoverflow.com/a/52561165/129130), [3](https://stackoverflow.com/a/52731065/129130), [4](https://stackoverflow.com/a/39401425/129130). I think TARGETDIR is used for [administrative installations](https://stackoverflow.com/a/5751980/129130), and INSTALLFOLDER for regular installation, but I have honestly not checked in detail. – Stein Åsmul Jul 08 '19 at 12:14
  • Just for reference, MSI expert Chris Painter: [How to define installation folder from command line parameter in Wix installer](https://stackoverflow.com/questions/24266720/how-to-define-installation-folder-from-command-line-parameter-in-wix-installer) and [WiX mailing list](http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Setting-installation-location-from-command-line-td5828080.html). – Stein Åsmul Jul 08 '19 at 12:21
  • Actually you can solely use `TARGETDIR` to define your installation folder. The `INSTALLFOLDER` seen in most examples is superfluous, it just simplifies the examples a little bit. You need a custom action to set the default path though. – zett42 Jul 08 '19 at 16:59
  • @SteinÅsmul You're totally missing the point with your links. It's *NOT* about setting the installation folder on the command line, that's easy. It's about setting the installation folder **specifically** with TARGETDIR. – The Welder Jul 10 '19 at 13:02

0 Answers0