Why does the TARGETDIR directory need a name? [duplicate] - wix

This question already has answers here:
In WiX files, what does Name="SourceDir" refer to?
(3 answers)
Closed 6 years ago.
In wix projects you will generally see a line like
<Directory Id="TARGETDIR" name="SourceDir">
But why does the name need to be set here? From what I understand the name property specifies the name of the generated folder on the machine doing the installing. But no SourceDir folder will be created, so why is it needed?

UPDATE:
It turns out this question has been asked before. Check this post for an explanation from Wix creator Rob Mensching: In WiX files, what does Name="SourceDir" refer to?
TARGETDIR plays a special role in the resolution of an MSI file's Directory table. Specifically it forms the root of the source and target directory trees. This is indicated in the MSI file by the null value in the Directory_Parent column:
After directory resolution SourceDir will point to the path where the MSI is running from. Furthermore TARGETDIR will be the parent folder for most built-in Windows directories such as ProgramFilesFolder and ProgramMenuFolder as illustrated in the image above.
So in short SourceDir is defined to hold the location of the running MSI file, and this location is necessary to know in order to resolve the source locations on the distribution media for each file to install.
A target location is a full installation path for a file: C:\Program Files\My App (where the file is going). A source location is the full source path for a file: [SourceDir]Program Files\My App (where the file is coming from).
It is late, please let me know if this wasn't clear.

Related

WiX: Change .msi Directory and CustomAction table with changes to be used by .msp Patch file

with the Wix Toolset v3.11 I have created a .msi file for my application (let's say version 1.1) with a Directory element that targets the LocalAppDataFolder and puts a Temp folder underneath. This structure is used with a DirectoryRef element to put some files there that are accessed within a custom action on InstallFinalize. Now I generated a Patch (version 1.2) that adds some files in the Temp folder. But I want that folder to be in the TARGETDIR now. So I changed
<Directory Id="LocalAppDataFolder">
<Directory Id="APPDATA_TEMP" Name="Temp" />
</Directory>
to
<Directory Id="MY_TEMP_PATH" Name=".">
<Directory Id="APPDATA_TEMP" Name="Temp" />
</Directory>
underneath the
<Directory Id="TARGETDIR" Name="SourceDir">
structure. For the Patch to be applied correctly I opened the .msi file that's referenced in the registry (under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\...\Products{GUID}\InstallProperties\LocalPackage) with the Orca tool and edited the corresponding values in the Directory table. I also edited the CustomActions table to reference the new path as it is used as a parameter there. So, now when I install the Patch it puts all the files (changed and new ones) in the LocalAppDataFolder as it did with the initial install. The custom action is called with the correct parameter though.
Is there a way to change the "base" msi to target my new Temp folder or, alternatively, somehow tell the Patch to use the new folder regardless of the initial path?
The goal is to apply the patch without having to uninstall the application first.
Any help on how to achieve that is greatly appreciated.
Finally we found a solution. So here's what solved our problem, should anyone ever come across something similar:
We found the actual path of the LocalAppDataFolder in two locations in the registry: The first entry is located in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders. The second one is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData...\Components. The entry with the component ID that puts the files in the Temp folder holds exactly one value, which is the path to the first file in that component. We changed both paths to our new temp folder.
Now the patch extracts the files correctly to the new temp folder and the custom action can process them further.

Is there a way to get directory's actual path in wix?

I want to bind a property to a directory's id path. Is there a way to get the directory's actual path from a directory id or somehow ?
The Directory element Id attribute in WiX becomes the Directory Table Directory column in the build Windows Installer MSI database. During installation, directory resolution is performed by the CostFinalize Action. After this point you can Using a Directory Property in a Path.
The directories in the Directory table specify the layout of an
installation. When the Windows Installer resolves these directories
during the CostFinalize action, the keys in the Directory table become
properties set to directory paths. The installer also always sets a
number of standard System Folder Properties to system folder paths.
For example in a RegistryValue element you could give a value of [INSTALLLOCATION].

WiX: Copy a file from local folder to installation folder

I'm using a WiX setup project to build an MSI package.
I want the MSI, to do a copy of the given file during the installation to the installation folder from the one, where the .msi file is running from.
I read on WiX a bit, and what I found is the <CopyFile... /> element supposed to do that.
Appreciate your help.
Actually I've figured out what the issue is.
The problem is that the SourceDirectory of the CopyFile element supposed to point to the Directory tag id.
Instead, I've used SourceProperty attribute of the CopyFlie tag, and also defined a Property separately, which made the use of the CopyFile element correct.
So it worked.

how can I find out the location from where the msi installer is being run

Can anyone tell me how can I find out the location from where the msi installer is being run.
For example I have my Sample.msi and Manuals folder in the folder InstallerExample on the Desktop.
I need this information so that I can use it in File/#Source, like the one given below.
<File Id="MyFileId" Name="MyFile" Source="[SourceDir]Manuals" KeyPath="yes" >
SourceDir should have value C:\Users\bla\Desktop\InstallerExample\Manuals
It will be great if anyone can please help me with this.
I just had the same problem as I wanted my custom action to read a file from where my MSI was so i needed the path. I was able to locate it using
TARGETDIR
According to the MSDN documentation TARGETDIR is
the root destination directory for the installation
Also according to MSDN, SourceDir is
the root directory that contains the source cabinet file or the source file tree of the installation package
So the SourceDir property points to a real directory: the one where your MSI file sits. You can see this in the installer log when installing with msiexec /lvx* installer.log installer.msi.
However, for some reason SourceDir is completely ignored when resolving the TARGETDIR. The TARGETDIR must be either set explicitly (e.g. on the command line) or else it resolves to ROOTDRIVE. If ROOTDRIVE is not explicitly set then it is the root of the drive with the most free space.

WIX Change Initial install directory

When I make my WIX Build setup,
by default it installs into the ProgramFIles directory.
I want to change this to the Application Local Data directory,
How would I do this?
Thanks
You can use folder definitions like this:
<Directory Id='LocalAppDataFolder'>
<Directory Id='MyAppFolder' Name='MyApp' />
</Directory>
To find the IDs of other system folders like LocalAppDataFolder, take a look at the System Folder Properties section of the Windows Installer Property reference.
Are you doing a per-user installation using the built in dialog sets?
If you set Package/#InstallScope="perUser" then the default installation folder will automatically be set to [LocalAppDataFolder]Apps\[ApplicationFolderName]
For more information refer to the WiX manual.