WiX Define used in directory specification - wix

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)'.

Related

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>

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.

Setting directory using RegistrySearch for not exist directory doesn't work

I am using RegistrySearch to set a property that is one of my directory and i see that when the registry value is of sub directory that doesn't exist than he value of the directory is not set, why is that?
In my case the ROLESDIR will be set to empty if the target directory doesn't exist (while the registry still point to it) --> the end result is that the the RoleDir will be installed directly under CONFDIR
<Property Id="ROLESDIR">
<RegistrySearch Id="ROLESDIRRegistry" Type="directory" Root="HKLM" Key="Software\DummyName\UCM" Name="ConfRolesDirectoryPath" />
</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="SDIR">
<Directory Id="CONFDIR" Name="Conf">
<Directory Id="ROLESDIR" Name="Roles">
<Directory Id="RoleDir" Name="MyRole" />
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
Your question isnt very clear,
Can you give an example of the registry value.
I have used this in the past.
<Property Id="INSTALLDIR">
<RegistrySearch Id="INSTALLDIRRegistry" Type="raw" Root="HKLM" Key="Software\Manufacturer\Product" Name="InstallDir" />
</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" Name="ProductName">
This sets the INSTALLDIR to the location of the path in the registry value. I think in your case you are trying to set the path of a folder which already has a path defined to it by the wix code.
You might want to try something like this
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ROLESDIR" Name="Roles">
<Directory Id="RoleDir" Name="MyRole" />
</Directory>
<Directory Id="ProgramFilesFolder">
<Directory Id="SDIR">
<Directory Id="CONFDIR" Name="Conf" />
</Directory>
</Directory>
</Directory>
Hope that helps