Wix: change installation folder tree - wix

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

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

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>

How to create a folder in the windows folder using wix 3.8 installer

I need to install file in the regular installation folder (i.e. c:\program files\mycompany\myapp) but I also need to copy files into a subfolder located in the windows folder i.e. c:\windows\myfolder.
While I have no problem with the "install" folder, I can't see how to create a sub-folder in c:\windows?
Any ideas?
Thanks.
Thierry
UPDATE:
I probably should have been a bit more precise and provide additional information. This is the xml I have:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MyCompany">
<Directory Id="ClientFolder" Name="Client">
</Directory>
<Directory Id="ServerFolder" Name="Server">
</Directory>
</Directory>
</Directory>
</Directory>
<Directory Id="WindowsFolder" Name="WindowsFolder">
<Directory Id="MyFolder" Name="MyFolder"></Directory>
</Directory>
</Fragment>
When I try to compile my wix project, I get the following error:
Error 1 : The Directory with Id 'WindowsFolder' is not a valid root directory.
There may only be a single root directory per product or module and its Id attribute
value must be 'TARGETDIR' and its Name attribute value must be 'SourceDir'
PS: I'm new to this and I'm reading a book on how to use Wix, but I need this asap, so please be patient with me :). Thank you.
You create Directory elements based on System Folder Properties. Specifically the WindowsFolder property. Then create a child Directory element for your folder.
You should have very strong justification before doing this as this is an operating system area. I typically tell developers no unless they have a very, very good reason.
The penny dropped!!
You need to add a directory reference directly under
<Directory Id="TARGETDIR" Name="SourceDir">
along with the rest of your directories. You'll end up with something like this
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MyApp">
<Directory Id="ClientFolder" Name="Client"/>
</Directory>
</Directory>
<Directory Id="WindowsFolder">
<Directory Id="MyFolder" Name="MyFolder"/>
</Directory>
</Directory>
Where the WindowsFolder will tell the installer to use the "windows" folder and to use the sub folder within it, just set the Directory your ComponentGroup (or other) to MyFolder i.e.
<ComponentGroup Id="MyFolderComponents" Directory="MyFolder">
..
..
</ComponentGroup>
That regular installation folder of yours is based on a tree that will have ProgramFilesFolder somewhere, and then your subfolder name. You do the same for the Windows folder using the standard Windows Installer property:
Windows Folder
which is one of this bunch:
Property Reference

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.