22

In legacy Visual Studio Deployment Project installers, passing a command-line parameter that specified a value for TARGETDIR allowed me to override the default installation location (most of my installations take place without user interaction, so command-line automation is used heavily). However, the impression I'm getting is that WiX (by default) uses TARGETDIR for something different. While I can (and will) update our command-line tools to change the parameter name, that still leaves all of our existing installations that would need to be touched manually (a non-trivial effort).

Is there any way to override the installation location in a WiX package by specifying TARGETDIR without breaking anything?

Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
  • http://stackoverflow.com/questions/15921078/wix-toolset-create-directory-in-root-disk-system-disk-or-c-and-copy-files-i this worked for me. Using the "anotherlocation" – WtFudgE Jan 24 '14 at 10:28

1 Answers1

29

After doing more digging, it looks like my previous experience is a result of behavior specific to VSDPROJ's (and possibly InstallShield), wheras WiX is conforming to the Windows Installer.

As I discovered at this link, TARGETDIR is actually supposed to represent the root of the drive with the most free space available (assuming there's more than one). That's why WiX projects have directories nested under there for Program Files, etc. Visual Studio actually adds a custom action that overrides this property to the full installation path.

I was able to accomplish what I wanted by doing two things:

  1. Change all of my components and component groups to install to TARGETDIR instead of INSTALLFOLDER (the default directory that WiX put in there)
  2. Add a custom action that sets the value of the TARGETDIR property to the installation path, assuming one wasn't passed in from the command line.

To do that, I added this under the <Product> tag:

<CustomAction Id="SetTARGETDIR" Property="TARGETDIR" 
              Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" 
              Execute="firstSequence" />

And this within the <InstallExecuteSequence> tag:

<Custom Action="SetTARGETDIR" Before="CostFinalize">TARGETDIR=""</Custom>
Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
  • This solved my issue around this very topic! Thank you so much for sharing it. – joebalt Aug 29 '12 at 17:44
  • This doesn't do anything for me... It still installs my stuff in E. – WtFudgE Jan 24 '14 at 09:49
  • 1
    @WtFudgE: Your best bet would be to post another question. – Adam Robinson Jan 24 '14 at 13:00
  • 2
    From Wix 3.x on I would write this like `NOT Installed AND NOT TARGETDIR`. Note that I added `NOT Installed` to the condition, because installation directories should only be changed on first install. In maintenance mode, Windows Installer will set directory properties to the actual install paths which shouldn't be changed. – zett42 Jul 08 '19 at 18:35
  • 11
    This WiX software is so obscure and so badly documented. Without Stack Overflow it's impossible to use it. – Endrju Feb 10 '20 at 20:21
  • This is working for command line, but causing issues in UI installation. Also this appears as a hack. Seems not a recommended Wix solution. – thanga May 25 '20 at 13:48