Dynamically set install dir in WiX from environment variable - wix

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.

Related

WiX Define used in directory specification

I'm trying to use a 'define' in a directory name on wix 3.11.
I've tried less-complex forms of the define,
like trying with the define as AppName="My App 2019", (without the nested AppYear).
and I get the same error. What am I doing wrong, and how do I accomplish this?
<?Define AppYear="2019"?>
<?Define AppName="My App $(var.AppYear)"?>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="$(var.Manufacturer)" >
<Directory Id="INSTALLDIR" Name="$(var.SolutionName)" >
<Directory Id="APPDIR" Name="Application Files" >
<Directory Id="APPSUBDIR" Name="$(var.AppName)" />
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
I get the following compiler error when compiling:
Error Undefined preprocessor variable '$(var.AppName)'.

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?

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>

Can you set TARGETDIR to be a command line parameter?

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.