Can you set TARGETDIR to be a command line parameter? - wix

I have generated an msi which I'd like to be able to change the default installation directory of and I know that you can change WIX properties using command line parameters, but I can't seem to get this working for TARGETDIR like this:
Installer.msi TARGETDIR=C:\
My Directory fragment is:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="SystemFolder"/>
<!-- Desktop-->
<Directory Id="DesktopFolder"/>
<Directory Id="ProgramFilesFolder">
<Directory Id="DIR_Company" Name="Company Name">
<Directory Id="DIR_SubDir" Name="Sub Directory" >
<Directory Id="INSTALLDIR" Name="My Product">
<Directory Id="DIR_ONE" Name="ONE" />
<Directory Id="DIR_TWO" Name="TWO" />
<Directory Id="DIR_THREE" Name="THREE" />
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>
Is this just not possible, or is it my syntax?

I suspect this is because you have predefined folders in your directory hierarchy, for instance, ProgramFilesFolder. Even though you set the TARGETDIR via the command line, it gets overwritten with the well-known location of your Program Files and all sub folders become relative.
As a workaround, you can set INSTALLDIR from the command line. If you give it a full path, it will overwrite the initial hierarchy you define in your WiX authoring.

Related

Change default install dir in WiX Toolset

I want the default directory to be: C:\MyApp
Unfortunately, whatever I do, the default directory is still C:\Program Data(x86)\MyApp.
How can I change it?
My current directory structure looks like this:
<SetDirectory Id="WINDOWSVOLUME" Value="[WindowsVolume]"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="WINDOWSVOLUME">
<Directory Id="APPLICATIONFOLDER" Name="MyApp"/>
</Directory>
</Directory>
Can you explain to me, what am I doing wrong?
Greetings

WiX installation into nested folder

I want to install my application by default according to schema:
Program Files/Company Name/Product Name
I write in WiX script:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ApplicationRoot" Name="Company Name">
<Directory Id="APPLICATIONFOLDER" Name="Product Name">
</Directory>
</Directory>
</Directory>
</Directory>
Then all components are targeted to APPLICATIONFOLDER. However, setup installs files into
Program Files/Company Name/
What is wrong?

Dynamically set install dir in WiX from environment variable

I'm new to MSI development (with WiX or otherwise) and I'm trying to read the value of an environment variable and use it as the installation directory. My msi is gui-less too and giving the user the option to override the path is not permitted.
I can successfully read the var with:
<SetProperty
Id="TARGETINSTALLDIR"
Value="[%MY_ENV_VAR]\My\Install\Path"
After="LaunchConditions"
Sequence="first" />
I can see in the msi logs the correct path retrieved.
I have tried the following to set the returned path:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="[TARGETINSTALLDIR]"/>
</Directory>
Also,
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="TARGETINSTALLDIR"/>
</Directory>
Failing that, I also tried to read the directory path within the ROOT Directory as shown below
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ROOT" Name="[%MY_ENV_VAR]">
<Directory Id="My" Name="My">
<Directory Id="Install" Name="Install">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="Path"/>
</Directory>
</Directory>
</Directory>
</Directory>
Is there some syntax I'm missing or am I fundamentally misunderstanding how this should be done?
Right, I figured it out.
Rather than using a SetProperty Element, I should have used a SetDirectory Element. The markup is simple;
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="APPLICATIONROOTDIRECTORY"/>
</Directory>
<SetDirectory Id="APPLICATIONROOTDIRECTORY" Value="[%MY_ENV_VAR]\My\Install\Path" Sequence="first" />
Hopefully this helps someone else out.

Wix Directory Confusion?

So I have my installer working, however the directory ID's have my confused.
Right now I have:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MainFolder" />
<Directory Id="APPFOLDER" Name="Utility" >
</Directory>
</Directory>
</Directory>
</Fragment>
My Component Group (for all my files to get moved) referenced "Utility", However it creates a Folder in Program Files called "Utility" and Not MainFolder/Utility.
How do I make it go to Program Files/Mainfolder/Utility instead of Just Program Files/Utility
thanks!
Your current Directory structure is set like this (MainFolder and Utility are under programFiles)
SourceDir
ProgramFiles
MainFolder
Utility
Change the Directory structure in your fragment like the code below it will create a structure like this (Utility is now under Mainfolder) Notice how the Directory element of the INSTALLFOLDER now doesn't have an end tag "/>"
SourceDir
ProgramFiles
MainFolder
Utility
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MainFolder" >
<Directory Id="APPFOLDER" Name="Utility" >
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>

Wix: change installation folder tree

I've a set of folder to be installed in different layouts for different users. For examle:
User1:
AppFolder
Dir1
Dir2
Dir3
User2:
AppFolder
Bin
Dir1
Dir2
Lib
Dir3
How it's possible?
Not a lot of detail in the question, so I'll have to guess a bit. You can treat Directories a lot like Properties. So, you could do something like:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="AppFolder" Name="PFiles">
<Directory Id="BinFolder" Name="Bin">
<Directory Id="Dir1" Name="Dir1" />
<Directory Id="Dir2" Name="Dir2" />
</Directory>
<Directory Id="LibFolder" Name="Lib">
<Directory Id="Dir3" Name="Dir3" />
</Directory>
</Directory>
</Directory>
</Directory>
<SetProperty Id="BinFolder" Value="[AppFolder]" After="CostFinalize">HOW_EVER_USER2_DETECTED</SetProperty>
<SetProperty Id="LibFolder" Value="[Dir2]" After="CostFinalize">HOW_EVER_USER2_DETECTED</SetProperty>
That may not be exactly correct but it'll get you close. You might also look at using a CustomAction element that uses the Directory and Value attributes to redirect if the Property mechanism doesn't work perfectly.
Also, like others have mentioned. This is weird. I'd suggest removing the requirement from the product. ;)