WIX 3.8 installer: Add files to a pre-existing folder - wix

How would I install files directly into a pre-existing folder on the user's computer? All documentation I read only explains creating a custom INSTALLDIR.
Eg. c:\ProgramFiles(x86)\ExampleFolderA\ExampleFolderB\InstalledFile.exe

You should first define the directory structure:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ExampleFolderAId" Name="ExampleFolderA">
<Directory Id="ExampleFolderBId" Name="ExampleFolderB" />
</Directory>
</Directory>
</Directory>
Note that the definition above does NOT create directories when the installation runs. In order for the directories to be actually "created" you have to either place files there (using Component elements), or explicitly state that the directory is empty.
Something like this:
<DirectoryRef Id="ExampleFolderAId">
<Component Id="SampleComponent" Guid="GUID-GOES-HERE">
<File Id="SampleFile" Source="C:\readme.txt" KeyPath="yes" />
</Component>
</DirectoryRef>
or
<DirectoryRef Id="ExampleFolderBId">
<Component Id="EmptyFolderComponent" Guid="GUID-GOES-HERE">
<CreateFolder />
</Component>
</DirectoryRef>
Hope you get the idea.

Related

Add resource files in wix installer

I have created a multi lingual app that uses 2 diferent resource files to manage the UI language, so when I build and execute my program, in my bin directory I have my app files and two folders, en-GB and pt-PT.
I am now trying to create a installer with Wix, for that I am defining the following directories:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="App" >
<Directory Id="LOCALEEN" Name="en-GB"/>
<Directory Id="LOCALEPT" Name="pt-PT"/>
</Directory>
</Directory>
</Directory>
</Fragment>
And then, I define the following components:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="App.resources.en.GB.dll" Guid="...">
<CreateFolder />
<File Id="App.resources.en.GB.dll" Name="App.resources.dll" Source="$(var.App.App_TargetDir)en-GB\App.resources.dll" />
</Component>
<Component Id="App.resources.pt.PT.dll" Guid="...">
<CreateFolder />
<File Id="App.resources.pt.PT.dll" Name="App.resources.dll" Source="$(var.App.App_TargetDir)pt-PT\App.resources.dll" />
</Component>
... Other components...
</ComponentGroup>
</Fragment>
When I rebuild my solution I get the following error:
'App.resources.dll' is installed in '[ProgramFilesFolder]\App\' by two
different components on an LFN system: 'App.resources.en.GB.dll' and
'App.resources.pt.PT.dll'. This breaks component reference counting.
I understand the problem, both resources dll are being copied to the installation folder, and not to the specific resources file... But I don't know how to solve it. Anyone can give any hints on how to solve this?
Just reference the directory where you want your components eg. Directory="LOCALEEN". There is no need to specify <CreateFolder />
I also recomend to maintain some kind of naming convention. Your Components and Fils have the same id. See https://stackoverflow.com/a/1801464/4634044. So this should do what you expect:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="C_EnglishLocale" Guid="..." Directory="LOCALEEN">
<File Id="Fi_EnglishLocale" Name="App.resources.dll" Source="$(var.App.App_TargetDir)en-GB\App.resources.dll" />
</Component>
<Component Id="C_PolnishLocale" Guid="..." Directory="LOCALEPT">
<File Id="Fi_PolnishLocale" Name="App.resources.dll" Source="$(var.App.App_TargetDir)pt-PT\App.resources.dll" />
</Component>
</ComponentGroup>
</Fragment>

WIX Writing user data into config file

I would like to ask a WiX installer question. I created a working installer that does many things already. I still need to ask the user for some specific information (the GUI is already done), and write it into a config file.
From this snippet, I think I could use the INSTALLFOLDER global variable.
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="IISROOT" Name='WebDir'>
<Directory Id="INSTALLFOLDER" Name="IVRDesigner">
</Directory>
</Directory>
</Directory>
This is the part, when I want to use that. This code is taken from a tutorial, should work well, if the source tag is filled properly. The ..\src\Web.config is just a dummy, so the code can compile. The default installed path for the web.config file will be C:\inetpub\wwwroot\myfolder, but the user can change this during the installation.
The question is: how could I use the global variable here, or what kind of solution, do you recommend?
Thanks in advance.
<Component Id="ConfigureWebConfig" Guid="*">
<File Id="Web.config" Name="MyConfigfile" Vital="yes" KeyPath="yes"
Source="..\src\Web.config" />
<util:XmlFile Id="AppConfigSetConnStr" Action="setValue"
Permanent="yes" File="[#Web.config]"
ElementPath="/configuration/connectionStrings/add[\[]#name='GeoIVRDesignerEntities'[\]]" Name="connectionString"
Value="data source=[DBSERVER];" />
</Component>
Under the Product tag I would add the properties that I want to be able to change in the config file like this:
<Property Id="BUILDRAN" Value="INSTALLER"/>
<Property Id="EMAIL_RECEIPIANT" Value="thisisnotme#notthere.com" />
Create the Fragment for the Directory Structure
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir" >
<Directory Id="BasicDir" Name="Dev_Home">
<Directory Id="BasicDirSuite" Name="TEST">
<Directory Id="INSTALLFOLDER" Name="DesignPatterns" />
</Directory>
</Directory>
</Directory>
</Fragment>
Declare another Fragment for the transformation of the config file
<util:XmlFile Id="AppConfigSetBuildRan" Action="setValue" Permanent="yes" File="[#App.config]"
ElementPath="/configuration/applicationSettings/MyApp.Properties.Settings/setting[\[]#name='BuildRan'[\]]/value"
Value="[BUILDRAN]" />
<util:XmlFile Id="AppConfigSetEmail" Action="setValue" Permanent="yes" File="[#App.config]"
ElementPath="/configuration/applicationSettings/MyApp.Properties.Settings/setting[\[]#name='TestValue'[\]]/value"
Value="[EMAIL_RECEIPIANT]" />
If you want you can create your own custom dialog to let the End user enter values for the properties [BUILDRAN] && [EMAIL_RECEIPIANT], or you could use the command line and set the properties with parameters
msiexec /i My.msi BUILDRAN=SuperDebug EMAIL_RECEIPIANT=you#home.com

Wix creates an application data directory which is read only

I'm creating a folder structure in WiX in the following manner:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MyApp">
</Directory>
</Directory>
<Directory Id="CommonAppDataFolder">
<Directory Id="CONFIGFOLDER" Name="MyAppConfig">
<Directory Id="Configdir1" Name="Configdir1">
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="MyApp"/>
</Directory>
</Directory>
I'm then populating these directories later on using Component tags like this:
<ComponentGroup Id="ProductConfiguration" Directory="CONFIGFOLDER">
<Component Id="ConfigFile1" Guid="*">
<File Id="ConfigFile1.xml" Name="ConfigFile1.xml" Source="..\Configuration\ConfigFile1.xml" Vital="yes" KeyPath="yes" DiskId="1"/>
</Component>
<Component Id="ConfigFile2" Guid="*">
<File Id="ConfigFile2.xml" Name="ConfigFile2.xml" Source="..\Configuration\ConfigFile2.xml" Vital="yes" KeyPath="yes" DiskId="1"/>
</Component>
<Component Id="ConfigFile3" Guid="*">
<File Id="ConfigFile3.xml" Name="ConfigFile3.xml" Source="..\Configuration\ConfigFile3.xml" Vital="yes" KeyPath="yes" DiskId="1"/>
</Component>
</ComponentGroup>
My problem is this: WiX creates the Configuration directory (CommonAppDataFolder/MyAppConfig) as a read only folder. Since it's full of application data, users need to be able to modify its contents without having admin privileges. I can create other folders in the CommonAppDataFolder programmatically, which do not require admin privileges.
How do I set the write privileges for my folder in WiX?
Turns out that the answer looks something like this:
<Directory Id="MYFOLDER" Name="My folder name">
<Component Id="MyFolderComponent" Guid="*">
<CreateFolder Directory="MYFOLDER">
<Permission User="Everyone" GenericAll="yes" />
</CreateFolder>
</Component>
</Directory>
CommonAppDataFolder is a per-machine store and so requires elevated privileges to write to. If you want a per-user store, use the AppDataFolder or LocalAppDataFolder directory properties instead.

"ICE38: Component installs to user profile" error for a specific component

I am trying to write a Windows Installer script in WiX 3.6 with a per-machine and x64 architecture only setting. I have the following project structure (shortened):
<Directory Id="ProgramFiles64Folder" Name="PFiles">
<Directory Id="APPLICATIONFOLDER" Name="My Company">
<Directory Id="ProductFolder" Name="My Product">
<Component Id="MainComponent" Guid="" Win64="yes" KeyPath="yes">
...
</Component>
<Directory Id="DataFolder" Name="Data">
<Directory Id="Machine" Name="Machine" >
<Directory Id="MachinesFolder" Name="Machines">
<Component Id="Machine1" Guid="{74341536-72DF-48C3-95E8-2851D9FA8318}" Win64="yes" KeyPath="yes">
...
</Component>
</Directory>
<Directory Id="TemplateFolder" Name="Template">
<Component Id="TemplateFiles" Guid="{A0D0C225-D604-4B84-971D-41687A30EC36}" Win64="yes" KeyPath="yes">
<File Id="Template1.rsbak" Source="$(var.SolutionDir)bin\Release\File1.rsbak" />
...
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
The problem is that I receive the error ICE38: Component TemplateFiles installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file for the TemplateFiles component when I compile. What confuses me is that I use a similar structure in another project (working), and have several components with the exact same setup in my project (not shown above). Why does this - and this only - component insist on installing to the user profile when all others get installed correctly, to Program Files?
Looks like there's significant difference for msi between Program Files and Users\UserName\Documents folders. The last is referenced in your example:
<Directory Id="DataFolder" Name="Data">
I came to the similar problem and found an answer in the blog post - https://robmensching.com/blog/posts/2007/4/27/how-to-create-an-uninstall-shortcut-and-pass-all-the/
In short you need to define RegistryKey on HKCU root as subelement to Component and add RemoveFolder element as subelement to Directory. See the link above for full example. In addition:
Remove KeyPath attribute from Component element
RemoveFolder possibly have to be defined for all folders. I used dummy component with no file inside for that

Copy file from setup location to another location in wix on install

I have created an msi setup file which includes some files in a "Sample" folder which should be copied to a temp folder. Anybody suggest how to do this?
Something like this:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MyVendor" Name="MyVendor">
<Directory Id="INSTALLDIR" Name="MyDir">
<Component Id="MyFileId" Guid="...G1...">
<File Id="MyFileId" Name="MyFile" Source="...blabla...\MyFile" KeyPath="yes" >
</File>
</Component>
<DirectoryRef Id="TARGETDIR">
<Component Id="MyFileCopyId" Guid="...G2...">
<RemoveFile Id="MyFileRemoveId" Name="MyFile" On="install" Directory="MyCopyDir" />
<CopyFile Id="MyFileCopyId" FileId="MyFileId" DestinationDirectory="MyCopyDir" />
</Component>
<Feature Id="MyFeature" ... >
<ComponentRef Id="MyFileId" />
<ComponentRef Id="MyFileCopyId" />
The important Xml element is CopyFile. You need to create a new component that is a copy of the first one (with different ids, guids, ... of course). Both components needs to be declared in a feature.
CopyFile element is your friend. You can nest it under the original File element a number of times, depending on how many times you need to copy it. Put the correct destination folder(s) and let Windows Installer do the rest.