WiX: preserving recursive directory structure during component transfer - visual-studio

Wix 3.11.2 and Visual Studio Community 2019 here. My project has the following directory structure:
...\Source\Repos\my-app-setup\
my-app-setup\
bin\
obj\
testo\
fizz\
abc\
def\
ghi\
abba.txt
buzz\
bar.txt
foo.txt
my-app.exe
my-app-setup.wixproj
my-app-setup.wxs
my-app-setup.sln
Where my my-app-setup.wxs file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">​
<Product Id="*" Name="MyApp" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="1e540666-dda2-4cbe-91b7-ac9525d96c86">​
<Package Description="MyApp tool" Compressed="yes" />​
​
<MediaTemplate EmbedCab="yes"/>​
​
<Directory Id="TARGETDIR" Name="SourceDir">​
<Directory Id="ProgramFilesFolder">​
<Directory Id="INSTALLFOLDER" Name="MyApp" />​
</Directory>​
​
<Directory Id="DesktopFolder" Name="Desktop">​
<Component Id="ApplicationShortcutDesktop" Guid="*">​
<Shortcut Id="ApplicationDesktopShortcut"​
Name="MyApp"​
Description="Shortcut for MyApp"​
Target="[INSTALLFOLDER]my-app.exe"​
WorkingDirectory="INSTALLFOLDER"/>​
<RemoveFolder Id="DesktopFolder" On="uninstall"/>​
<RegistryValue​
Root="HKCU"​
Key="Software/MyApp"​
Name="installed"​
Type="integer"​
Value="1"​
KeyPath="yes"/>​
</Component>​
</Directory>​
</Directory>​
​
<Component Id="FooTxtComponent" Directory="INSTALLFOLDER">​
<File Source="testo/foo.txt" />​
</Component>​
​
<Component Id="AbbaComponent" Directory="INSTALLFOLDER">​
<File Source="testo/fizz/abc/def/ghi/abba.txt" />​
</Component>​
​
<Component Id="ExecutableComponent" Directory="INSTALLFOLDER">​
<File Source="my-app.exe" />​
</Component>​
<Feature Id="MainFeature" Title="MyApp" Level="1">​
<ComponentRef Id="FooTxtComponent" />​
<ComponentRef Id="AbbaComponent" />​
<ComponentRef Id="ExecutableComponent" />
​
<ComponentRef Id="ApplicationShortcutDesktop" />​
</Feature>​
</Product>​
</Wix>
So it basically just copies a bunch of files from the project into the C:\Program Files (x86)\MyApp directory and then creates a shortcut (to the EXE) on the desktop. Simple stuff.
When I build this and run the MSI the resulting C:\Program Files (x86)\MyApp directory looks like this:
C:\Program Files (x86)\
MyApp\
foo.txt
abba.txt
my-app.exe
So WiX is just plucking the files I specified and dropping them into the MyApp directory, at the same level as the EXE file. I don't want this; I want to preserve the same recursive directory structure as what exists in my VS project. So instead of the above I would like the WiX MSI to generate:
C:\Program Files (x86)\
MyApp\
testo\
fizz\
abc\
def\
ghi\
abba.txt
foo.txt
my-app.exe
What is the simplest way to accomplish this?
Thanks!

You need to nest the folders as shown in this sample (towards bottom): https://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with
Illustration:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="Example">
<Component>
<File Source="example.exe"/>
</Component>
</Directory>
</Directory>
</Directory>
Maybe also check:
My WiX Quick-Start Link Collection.
https://www.firegiant.com/wix/tutorial/

Related

Wix Toolset - how to install a file to a completely different directory and not as a root subdirectory?

For my application, most of the files need to be installed to a directory in ProgramFiles, and one other file needs to be installed in a directory in AppData/Local.
Here is an example of what I have so far:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Folder1" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="AppID" Directory="INSTALLFOLDER">
<Component Id="AppID">
<File Source="$(var.myApp.TargetPath)" />
</Component>
<Component Id="OtherFile" Guid="INSERT-GUID_HERE">
<File Id='OtherFile' Name='OtherFile' Source="otherfile" KeyPath='yes' />
</Component>
<Component Id="CopyId">
<CopyFile Id="CopyId" FileId="OtherFile"
DestinationDirectory="LocalAppDataFolder" />
</Component>
</Fragment>
I've tried to copy the other file to AppData/Local but this won't compile and gives the error:
Unresolved reference to symbol 'Directory:LocalAppDataFolder' in section 'Fragment:'
Ideally, I want the other file to be in directory in AppData/Local, and not in ProgramFiles at all.
Application Launch: Consider doing file-copying on application launch instead of as part of the setup. Easier to implement, debug and change as you need to.
Fix: Try just adding this directly under the TARGETDIR element. This ensures that the standard directory LocalAppDataFolder is part of the compiled MSI file's Directory table:
<Directory Id="LocalAppDataFolder" Name="AppData">
Alternatively, here is a larger mock-up:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupProject2" />
</Directory>
<Directory Id="LocalAppDataFolder" Name="AppData">
<Directory Id="AppRootDirectory" Name="MyApplication">
<Component Id="Test" Feature="ProductFeature" Guid="{11111111-1111-1111-1111-A73067A1AE95}">
<RemoveFolder Id="AppRootDirectory" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Something" Name="Flag" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</Directory>
</Directory>
</Directory>

ICE91 Wix in perMachine Installer

I am trying to make a perMachine Installer that is able to create files and folders in the PersonalFolder and LocalAppDataFolder of each user. I am getting always the warning message "warning LGHT1076: ICE91: ..." as listed below. When I install as an Administrator the file and folder is created despite the warning, but when I try the installer as standard user no file and no folder is created on the user profile. What could be the solution?
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="PFInstallDir" Name="Example">
<Component Id="ApplicationFiles" Guid="12345678-1234-1234-1234-222222222222">
<File Id="ApplicationFile1" Source="notepad.exe"/>
</Component>
</Directory>
</Directory>
<Directory Id="CommonFilesFolder">
<Directory Id="CFInstallDir" Name="Example">
<Component Id="CommonApplicationFiles" Guid="12345678-1234-1234-1234-222222222223">
<File Id="ApplicationFile2" Source="notepad.exe"/>
</Component>
</Directory>
</Directory>
<Directory Id="CommonAppDataFolder">
<Directory Id="CAInstallDir" Name="Example">
<Component Id="CommonAppDataApplicationFiles" Guid="12345678-1234-1234-1234-222222222224">
<File Id="ApplicationFile3" Source="notepad.exe"/>
</Component>
</Directory>
</Directory>
<Directory Id="PersonalFolder">
<Directory Id="InstallDirPersonal" Name="ExampleDocs">
<Component Id="ApplicationPersonalFiles" Guid="12345678-1234-1234-1234-222222222225">
<CreateFolder />
<RemoveFolder Id="RemoveMyExampleDir1" On="uninstall" Directory="InstallDirPersonal"/>
<RegistryKey Root="HKCU" Key="Software\MyCompany\Documents">
<RegistryValue Name="MainExe" Value="1" KeyPath="yes" Type="integer" />
</RegistryKey>
<File Id="Notepad.MyExe"
Source="notepad.exe" DiskId="1" Checksum="yes">
</File>
</Component>
</Directory>
</Directory>
<Directory Id="LocalAppDataFolder" Name="AppData">
<Directory Id="InstallDirAppDataPersonal" Name="ExampleLocals">
<Component Id="ApplicationPersonalDataFiles" Guid="12345678-1234-1234-1234-222222222226">
<CreateFolder />
<RemoveFolder Id="RemoveMyExampleDir" On="uninstall" Directory="InstallDirAppDataPersonal"/>
<RegistryKey Root="HKCU" Key="Software\MyCompany\Example">
<RegistryValue Name="MainExe" Value="1" KeyPath="yes" Type="integer" />
</RegistryKey>
<File Id="Notepad.MyExe1"
Source="notepad.exe" DiskId="1" Checksum="yes">
</File>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="DefaultFeature" Level="1">
<ComponentRef Id="ApplicationFiles"/>
<ComponentRef Id="CommonApplicationFiles"/>
<ComponentRef Id="CommonAppDataApplicationFiles"/>
<ComponentRef Id="ApplicationPersonalDataFiles"/>
<ComponentRef Id="ApplicationPersonalFiles"/>
</Feature>
</Product>
-- Build started: Project: SetupProjectPerUsrMachine, Configuration: Debug x86 --
warning LGHT1076: ICE91: The file 'Notepad.MyExe' will be installed to the per user directory 'InstallDirPersonal' that doesn't vary based on ALLUSERS value. This file won't be copied to each user's profile even if a per machine installation is desired.
warning LGHT1076: ICE91: The file 'Notepad.MyExe1' will be installed to the per user directory 'InstallDirAppDataPersonal' that doesn't vary based on ALLUSERS value. This file won't be copied to each user's profile even if a per machine installation is desired.
Problem solved!
http://www.installworld.com/index.php?option=com_content&do_pdf=1&id=146
"If the resource must be copied to each user’s profile, then add functionality to your package to do this. To achieve this, add a current user registry key (i.e., just a dummy registry key) and make this registry key the key path of the component which contains the resource. This means that the resource will be copied to the next user’s profile as part of the MSI self healing mechanism, provided that advertised entry points exist for the product."
http://blog.bittercoder.com/2007/02/28/wix-shortcuts/
<Component Id="StandAloneApplication" Guid="C8D5DB05-2D68-40e8-88D1-EF5BEA18DBE1">
<File Id="SomeCompanySomeProductHostApp"
Name="SomeCompany.SomeProduct.HostApp.exe"
DiskId="1"
Source="....buildSomeCompany.SomeProduct.HostApp.exe"
Vital="yes">
<Shortcut Advertise="yes"
Id="SomeCompanySomeProductHostAppShortcut"
Directory="ProgramMenuDir"
Name="My Product"
WorkingDirectory="INSTALLDIR"
Description="SomeProduct Application"
Icon="HostAppShortcutIcon.exe">
<Icon Id="HostAppShortcutIcon.exe"
SourceFile="....buildSomeCompany.SomeProduct.HostApp.exe" />
</Shortcut>
</File>
</Component>

How to Reference a Heat Output(wxs) in Wix (Command Line)

I am using heat.exe to generate a .wxs file to include files in my main installer. I have two questions:
Which switches would I use to register a DLL?
Once I have generated the output file how do I go about adding it to my "Main.wxs" file? (Please be pretty explicit, new to this)
I have looked around a lot for an answer to the second question and I always come up with something vague or for VS, I am working from the command line. Thanks!
This is what I have tried thus far: I get the error: (LGHT0103: The system cannot find the file "file") I get this error for all of my files.
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="cmp1D2A500FA963CF9DB333FD18154B94BC" Guid="{8DE755D7-F1F9-4EC3-BCD5-B72360B8752A}">
<File Id="filCBD973AD942425DC5F533B29866FEF5A" KeyPath="yes" Source="SourceDir\DLLs\FP7000-Camera.dll" />
</Component>
<Component Id="cmp4CC93670B061A60B94C1867DCFAAAED0" Guid="{717E0819-2842-4C0D-BFAB-30E4C8C66F7E}">
<File Id="fil7CEC0F75EDE8EEF9C7F6D563E8D04EF9" KeyPath="yes" Source="SourceDir\DLLs\libmfxsw64.dll" />
</Component>
<Component Id="cmpE80ACF08DF44E67E7583F35557C8EB02" Guid="{4CAA0627-45DB-4E34-9B4C-C54B5E21346C}">
<File Id="fil1E619A89A3D0D2FDE446E60B3D3EB2AF" KeyPath="yes" Source="SourceDir\DLLs\pthreadVC2.dll" />
</Component>
</ComponentGroup>
</Fragment>
You can cut the component nodes and paste them into the correct installation directory in your main wxs file. As an example you can check out this simple mock-up:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="put-guid-here"
Name="Example Product Name" Version="0.0.1"
Manufacturer="Example Company Name" Language="1033">
<Package InstallerVersion="200" Compressed="yes"
Comments="Windows Installer Package"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="Example">
<Component Id="FP7000-Camera.dll" Guid="*">
<File Id="FP7000-Camera.dll" Source="replace with path to FP7000-Camera.dll"/>
</Component>
further components can be added here.
</Directory>
</Directory>
</Directory>
<Feature Id="DefaultFeature" Level="1">
<ComponentRef Id="FP7000-Camera.dll"/>
</Feature>
</Product>
</Wix>
You should extract the COM data for your COM files. Here is a sample Heat.exe command. (Note: if your dll fails to load due to missing dependencies you might need to install your sdk setup before running the extraction):
heat file MyComFile.ocx -out MyComFile.wxs
the resulting, extracted COM data in MyComFile.wxs will look something like this:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Directory Id="dirE645D1B018BB48C41BDBE188A129817F" Name="wix310-binaries" />
</DirectoryRef>
</Fragment>
<Fragment>
<DirectoryRef Id="dirE645D1B018BB48C41BDBE188A129817F">
cut from here
<Component Id="cmpD8BB195A00599F06D2FF16982DBAA523" Guid="PUT-GUID-HERE">
<File Id="filBDC3CFD8FF09857ADE9793AF172F66E6" KeyPath="yes" Source="SourceDir\wix310-binaries\ITDetector.ocx">
<TypeLib Id="{D6995525-B33A-4980-A106-9DF58570CC66}" Description="ITDetector 1.0 Type Library" HelpDirectory="dirE645D1B018BB48C41BDBE188A129817F" Language="0" MajorVersion="1" MinorVersion="0">
<Class Id="{D719897A-B07A-4C0C-AEA9-9B663A28DFCB}" Context="InprocServer32" Description="iTunesDetector Class" ThreadingModel="apartment" Programmable="yes" SafeForScripting="yes" SafeForInitializing="yes">
<ProgId Id="ITDetector.iTunesDetector.1" Description="iTunesDetector Class">
<ProgId Id="ITDetector.iTunesDetector" Description="iTunesDetector Class" />
</ProgId>
</Class>
<Interface Id="{45D2C838-0137-4E6A-AA3B-D39B4A1A1A28}" Name="IiTunesDetector" ProxyStubClassId32="{00020424-0000-0000-C000-000000000046}" />
</TypeLib>
</File>
</Component>
to here
</DirectoryRef>
</Fragment>
</Wix>
Paste the component into your main wxs file in the appropriate Directory location. For example in INSTALLDIR as illustrated in the first WXS file above.
Finally a merged sample showing the main wxs file populated with the extracted component nodes from your heat.exe tool:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="put-guid-here"
Name="Example Product Name" Version="0.0.1"
Manufacturer="Example Company Name" Language="1033">
<Package InstallerVersion="200" Compressed="yes"
Comments="Windows Installer Package"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="Example">
<Component Id="FP7000-Camera.dll" Guid="*">
<File Id="FP7000-Camera.dll" Source="replace with path to FP7000-Camera.dll"/>
</Component>
<Component Id="cmpD8BB195A00599F06D2FF16982DBAA523" Guid="*">
<File Id="filBDC3CFD8FF09857ADE9793AF172F66E6" KeyPath="yes" Source="SourceDir\wix310-binaries\ITDetector.ocx">
<TypeLib Id="{D6995525-B33A-4980-A106-9DF58570CC66}" Description="ITDetector 1.0 Type Library" HelpDirectory="dirE645D1B018BB48C41BDBE188A129817F" Language="0" MajorVersion="1" MinorVersion="0">
<Class Id="{D719897A-B07A-4C0C-AEA9-9B663A28DFCB}" Context="InprocServer32" Description="iTunesDetector Class" ThreadingModel="apartment" Programmable="yes" SafeForScripting="yes" SafeForInitializing="yes">
<ProgId Id="ITDetector.iTunesDetector.1" Description="iTunesDetector Class">
<ProgId Id="ITDetector.iTunesDetector" Description="iTunesDetector Class" />
</ProgId>
</Class>
<Interface Id="{45D2C838-0137-4E6A-AA3B-D39B4A1A1A28}" Name="IiTunesDetector" ProxyStubClassId32="{00020424-0000-0000-C000-000000000046}" />
</TypeLib>
</File>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="DefaultFeature" Level="1">
<ComponentRef Id="FP7000-Camera.dll"/>
<ComponentRef Id="cmpD8BB195A00599F06D2FF16982DBAA523"/>
</Feature>
</Product>
</Wix>
If the above is unclear, please try to read this answer: How to run heat.exe and register a dll in wix

VS2010 Wix proj - How to pass a command line variable to be used as a directory name

We have a requirement to install the same software in multiple directories on the same machine. I want to install the software using a batch file. I am having difficulty using the variable I have passed in as a directory name. (I am using VS 2010).
Batch file code
msiexec /i "SetupProjectTestMultiInstalls.msi" CUSTOMER="TESTCUSTOMER"
However the path created is
C:\Program Files\SetupProjectTestMultiInstalls[CUSTOMER]
as oppose to what I want
C:\Program Files\SetupProjectTestMultiInstalls\TESTCUSTOMER
Here is my wix xml
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<?define MYVARIABLE = "Temp" ?>
<?define FORMDIR = "$(var.SolutionDir)WindowsFormsApplication1\bin\Debug\"?>
<Condition Message="CUSTOMER variable must be set in the command line">
CUSTOMER
</Condition>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="SetupProjectTestMultiInstalls">
<Directory Id="Customer" Name="[CUSTOMER]">
<Component Id="ConfigFiles" Guid ="4fdbee76-d149-11df-aa02-05feded72085">
<File Id="WindowsFormsApplication1.exe" DiskId ="1" Vital="yes" ReadOnly="no"
Name="WindowsFormsApplication1.exe"
Source ="$(var.FORMDIR)WindowsFormsApplication1.exe" />
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="SetupProjectTestMultiInstalls" Level="1">
<ComponentGroupRef Id="Product.Generated" />
<ComponentRef Id="ConfigFiles" />
</Feature>
</Product>
Any ideas
Thanks
Jake
You can do something like this using INSTALLDIR instead of CUSTOMER to pass the location from the command line :
msiexec /i "SetupProjectTestMultiInstalls.msi" INSTALLDIR="C:\Program Files\SetupProjectTestMultiInstalls\TESTCUSTOMER"
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name=".">
<Component Id="ConfigFiles" Guid ="4fdbee76-d149-11df-aa02-05feded72085">
<File Id="WindowsFormsApplication1.exe" DiskId ="1" Vital="yes" ReadOnly="no"
Name="WindowsFormsApplication1.exe"
Source ="$(var.FORMDIR)WindowsFormsApplication1.exe" />
</Component>
</Directory>
</Directory>
</Directory>
However, I don't think that you can run the installer several times to install the software to different places. If the Product Id is already used then it will probably do a repair instead of a fresh install.

How to remove custom actions binary on uninstallation?

When I'm uninstalling my product directory where custom action binary was placed stays. How can I delete it. Also strange named directory is created on installation - unistallation: "RSCustomActions.CA.dll-" and "RSCustomActions.CA.dll-0" (my binary name RSCustomActions.CA.dll)
My WIX code is
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="Product.Id" Name="Product">
<Directory Id="INSTALLLOCATION" Name="Product">
<!-- TEST -->
<Directory Id="Installer" Name="Installer">
<Component Id="InstallerFiles"
Guid="{0904DB36-2496-419c-A992-B7D86F068F12}">
<File Id="RSCustomActions.CA.dll" Name="RSCustomActions.CA.dll" Source="Binaries\RSCustomActions.CA.dll" />
</Component>
</Directory>
<!-- END TEST -->
<?include "Product.Files.wxi" ?>
</Directory>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder" Name="PMenu">
<Directory Id="ProgramMenuDir" Name="Aspose">
<?include "Product.ProgramMenu.wxi" ?>
</Directory>
</Directory>
<Component Id="Main" Shared="yes" Guid="{EDD4477A-D188-469c-B8D0-4423377C03C6}" Feature="Main.InstallFeatures">
<RemoveFolder Id="DeleteProgramMenuDir" Directory="ProgramMenuDir" On="uninstall" />
</Component>
</Directory>
"Product.Files.wxi" also contains
<Component Id="Product.Remove" Guid="{C6D9D74C-66E8-442a-8E53-78A8D0E2B24D}">
<RemoveFolder Id="Product.RemoveFolder.Action" On="uninstall"/>
</Component>
Please suggest any way how can I remove Installer folder and those strage folders with binary name.
Thanks!
Why do you need installing the CA DLL as a file of the product? You can simply put it to Binary table and forget about it, like this:
<!-- This is a reference to the DLL where all custom actions reside -->
<Binary Id="CustomActions" SourceFile="$(var.Root)\CA\CustomActions.CA.dll" />
And the custom action definition is something like this:
<!-- Sample CA definition -->
<CustomAction Id="MyAction" BinaryKey="CustomActions" DllEntry="MyActionMethod" />
Note that MyActionMethod should be defined in that CA assembly and marked appropriately. There's a good sample of this in dtf.chm in WiX distribution.
Hope this helps.

Resources