wix install xml file, edit file and copy to another location - wix

I am trying to install a XML file(Tomcat context file) and copy the file to another location inside Tomcat\config\Catalina\ using WiX.
Before copying the file to Tomcat, I want to edit some values in the Context xml. Here, I have modified the xml using the tag from WixUtilExtension.
Below is what I have Done:
<SetProperty Id="CopyLocation" Value="[%CATALINA_HOME]\conf\Catalina\" Before="AppSearch" Sequence="execute"/>
<DirectoryRef Id="INSTALLDIR">
<Directory Id="dirA99A3925C98F7E949CF98F783959A0E0" Name="MyInstallFolder">
<Component Id="cmp318E197D1FB960F5622BEB6879276359" Guid="{FFF02817-FA29-40B7-927A-E943C08A8774}">
<File Id="fil6674D3AD50416393E3C992B211173485" KeyPath="yes" Source="$(var.installfolder)\MyContext.xml" />
<util:XmlFile Id="DocBase" Action="setValue" Permanent="yes" File="[#fil6674D3AD50416393E3C992B211173485]"
ElementPath="//Context" Name="docBase"
Value="[INSTALLDIR]InstallFolder" SelectionLanguage="XPath" Sequence="1"/>
<CopyFile Id="Copy_File" DestinationProperty="CopyLocation" DestinationName="MyContext.xml" FileId="fil6674D3AD50416393E3C992B211173485"/>
</Component>
</Directory>
</DirectoryRef>
Below is the XML Sample:
<Context path="/XERService" docBase="NoValue">
</Context>
The issue is that I am able to modify the file that is installed to the installation path but the file which is copied to the Tomcat doesnot have the changes.

This is because the default sequence for the DuplicateFiles action (the MSI action that maps to CopyFile) happens before the SchedXmlFiles action. You should be able to override this by specifying the following:
<InstallExecuteSequence>
<Custom Action="SchedXmlFile" Before="DuplicateFiles" />
</InstallExecuteSequence>

Related

How to modify the component .xml file with utils:XmlFile using WIX?

I am trying to create an installer which also installs the xml-file depending on input values, entered in separate dialog. Here
</Component>
<Component Id="ConfigXMLDocument">
<File Id ="Config" KeyPath="yes" DiskId="1" Vital ="yes" Source="$(var.Server.ProjectDir)config.xml"/>
<CreateFolder Directory="INSTALLFOLDER">
<util:PermissionEx User="Users" ChangePermission="yes" GenericAll="yes"/>
</CreateFolder>
<util:XmlFile ElementPath ="root/Server/servername" File ="[INSTALLFORDER]config.xml" Sequence="1" Id ="SERVERNAME"
Action ="setValue" Value ="THIS VALUE IS NOT BEING SET" SelectionLanguage="XPath"/>
<util:XmlFile ElementPath ="root/Server/listenport" File ="[INSTALLFORDER]config.xml" Sequence="2" Id ="PORT"
Action ="setValue" Value ="THIS ONE EITHER"/>
</Component>
The problem is that there are no errors and all the paths are resolved correctly, but the installed file remains the same as original.
If I try to change any other XML-file, It works, but not the one installed.
I found simmilar issues online, but no answers fixed mine.
Is it possible that XmlFile is just changing file before file is installed? And what else can cause such problem?
It appeared to be not one, but two issues.
The first one was to use FIle ID instead of path, so I replaced this
File ="[INSTALLFORDER]config.xml"
with this:
File ="[#Config]"
But It still didn`t work, during the installation appeared an error that the installer cannot find the file config.xml, so i changed the InstallExecuteSequence to this:
<InstallExecuteSequence>
<Custom Action="SchedXmlFile" After="InstallFiles" />
</InstallExecuteSequence>
UPD. This still did not work fine. WIX could not open the file with error:
Failed to open XML file path/config.xml, system error: -2147024786
The error appeared to be that wix cannot recognize the BOM in the XML file for some reason:
<?xml version"1.0" encoding="UTF-8" ?>
So i just removed it.
Hope this helps.

Editing packaged file in WiX

WiX newbie here. I'm curious if this approach is possible using WiX.
Problem statement...
I am packaging some SQL files that I want to execute against some parameters that the user will enter at run time. Think connection string information. One of the parameters that the user can enter is the directory where they want the DB to be installed.
Current solution (doesn't work).....
To do this i'm packaging these files using heat. When it sucks in this files one of my SQL files has some tokens in them that a custom action looks for to basically do a find replace in the file. The problem is thatwhile it is indeed doing a find replace it's doing them against the source files that heat sucked in and not the files that exist in the .msi file.
Question 1...
Within the WiX workflow is there a way that via a custom action I can do processing on the files that are stored within the .cab or .msi file? If that is possible can someone show me an example of this?
Question 2 . . .
If question 1 isn't possible the other idea I had was to break the find replace SQL piece and the file install piece into separate msi file. So the first step would be to explode all the files I need into the install directory via one msi. The next msi would execute the SQL piece as at that point the files exist on the file system for me to do editing on. Does this sound like a sane approach to the problem? It could very well be that I'm trying to work around WiX and not with WiX here.
Current code snippets
<Product>
<!-- This is where this will be installed-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLFOLDER" Name="ZOLLData">
<Directory Id="SQLINSTALLFOLDER" Name="Sql" />
</Directory>
</Directory>
<!-- CUSTOM ACTION DEFINITIONS-->
<CustomAction Id="FindReplaceZEDSTextCA"
Return="check"
BinaryKey="GemstoneInPremiseInstallerCustomActions.CA.dll"
Execute="immediate"
DllEntry="FindReplaceText" />
<!-- Database Information-->
<util:User Id="SQLUser" Name="[SQLUSERNAME]" Password="[SQLPASSWORD]"/>
<sql:SqlDatabase Id="MasterDatabase" Database="master"
Server="[SQLSERVERNAME]"
User="SQLUser"/>
<InstallUISequence>
<Show Dialog="SqlConnectionDlg" After="CostFinalize" />
<Show Dialog="ProgressDlgCustom" After="SqlConnectionDlg"/>
</InstallUISequence>
<InstallExecuteSequence>
<Custom Action="FindReplaceZEDSTextCA" After="InstallFiles">
</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<DirectoryRef Id="INSTALLFOLDER" />
</Fragment>
<Fragment>
<ComponentGroup Id="SqlComponents">
<Component Id="CreateDatabase.sql" Directory="INSTALLFOLDER" Guid="6A2C6088-9302-451C-A01B-02D618D4AC27">
</Component>
</ComponentGroup>
</Fragment>
Thanks in advance.
The problem was the my custom action was set with Execute="immediate". This should have been Execute="deferred".

How to create msi installer which can install file located near by it?

How to create msi installer which can install file located near by it or fetch this file over http?
We want to create an msi installer with wix toolkit 3.9 that should distribute our virtual machine (size is bigger than allowed in cab files), hypervisor, register(unregister) powershell scripts and something else.
We cannot create MSI with big file.
I see two approaches:
We can put virtual machine image located near by msi installed and programming this installer to install image if it exists near by it.
d:> dir
myapp.msi
vm.vdi
We can agree with client that he must put vm image located near the msi installer manually, before run it.
Download this vm image with http. What are the options for this?
How I can do this ?
I do this like this:
<!-- This is a list of directories that are used by this product as installation locations or custom -->
<!-- action file search locations. -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="LocalAppDataFolder" Name="AppData">
<Directory Id="AppRootDirectory" Name="Lookd"/>
</Directory>
</Directory>
<DirectoryRef Id="AppRootDirectory">
<Component Id="SupplementalScripts" Guid="31693357-578d-4dde-aefc-92f413942810" KeyPath="yes" DiskId="1">
<CreateFolder/>
<RemoveFolder Id="RemoveAppRootDirectory" On="uninstall" />
<File Id="SupplementalScripts_Register" DiskId="1" Vital="yes" Source="dst\Scripts\Register.ps1" Checksum="no"/>
<File Id="SupplementalScripts_UnRegister" DiskId="1" Vital="yes" Source="dst\Scripts\UnRegister.ps1" Checksum="no"/>
<File Id="SupplementalScripts_Throw" DiskId="1" Vital="yes" Source="dst\Scripts\Throw.ps1" Checksum="no"/>
<RegistryKey Root="HKCU" Key="Software\CVisionLab\Lookd" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
<RegistryValue Name="Version" Value="[ProductVersion]" Type="string"/>
</RegistryKey>
</Component>
<Component Id="VirtualMachineDiskImage" Guid="daa7375f-7bd8-4e97-846a-db5f6e6b025a">
<CopyFile Id="VDIFile" SourceName="lookd.vdi" SourceDirectory="SOURCEDIR" DestinationDirectory="TARGETDIR" />
</Component>
</DirectoryRef>
But I recive and error when build:
error LGHT0094 : Unresolved reference to symbol 'Directory:SOURCEDIR' in section 'Product:{7BBA165B-9A8A-40D1-97FA-233F93426F83}'.
If 1 will work for you, then a WiX CopyFile should work. The source location of the copy would be the [SourceDir] property, and the destination some directory defined in your WiX.
If it's really that big, download may be tedious, but if you use it then do it from an app you install rather than run it from the MSI install.
Clarifying in response to comment: there are just two recommendations here that are separate and not related:
Use WiX CopyFile if you choose to copy the file from next to the MSI file to the client system.
If you choose the download option, doing that from the MSI will be tedious and very error prone. It may not even work given that VS custom actions have very limited (or no) access to the network. So do a download from the app you're installing and not the MSI, if you do in fact decide to download.

LGHT1076 / LGHT1076: Install a data file to localappdata

Using WiX, a file can be installed to ProgramFiles using the following:
<DirectoryRef Id="ApplicationBinDirectory">
<Component ...>
<File Id="..." KeyPath="yes" Source="..." />
</Component>
</DirectoryRef>
Now I want to do the same, but the target is a folder in local application data. The file really belongs there according to http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
<!-- this is the folder in %LOCALAPPDATA% -->
<Directory Id="LocalAppDataFolder">
<Directory Id="ApplicationLocalAppDataDirectory" Name="my folder name"/>
</Directory>
<DirectoryRef Id="ApplicationLocalAppDataDirectory">
<File Id="fil" KeyPath="yes" Source="..." />
</DirectoryRef>
But I get the following error and warning now:
installer.wxs(63) : error LGHT0204 : ICE38: Component ApplicationConfiguration installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file.
installer.wxs(64) : warning LGHT1076 : ICE91: The file 'fil' will be installed to the per user directory 'ApplicationLocalAppDataDirectory' 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.
Adding RegistryValue and RemoveFolder as I have to do it for start menu shortcuts doesn't change the message.
I'm kind of lost here. How do I install a file to local appdata? Please note that I want to install only 1 file there, in addition to the usual setup in program files.
This should help. It shows adding a registry key item to be the keypath:
http://nofoe.blogspot.com/2008/12/wix-it-must-use-registry-key-under-hkcu.html

Wix major upgrade; need different behaviors for different components [duplicate]

This question already has an answer here:
WiX custom action with DTF... quite confused
(1 answer)
Closed 2 years ago.
Okay! I have finally more closely identified the problem I'm having. In my installer, I was attempting to get a settings file to remain intact on a major upgrade. I finally got this to work with the suggestion to set
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallFinalize" />
</InstallExecuteSequence>
This is successful in forcing this component to leave the original, not replacing it if it exists:
<Component Id="Settings" Guid="A3513208-4F12-4496-B609-197812B4A953" NeverOverwrite="yes">
<File Id="settingsXml" KeyPath="yes" ShortName="SETTINGS.XML" Name="Settings.xml" DiskId="1" Source="\\fileserver\Release\Pathways\Dependencies\Settings\settings.xml" Vital="yes" />
</Component>
However, this is a problem. I have another component listed here:
<Component Id="Database" Guid="1D8756EF-FD6C-49BC-8400-299492E8C65D" KeyPath="yes">
<File Id="pathwaysMdf" Name="Pathways.mdf" DiskId="1" Source="\\fileserver\Shared\Databases\Pathways\SystemDBs\Pathways.mdf" Vital="yes"/>
<File Id="pathwaysLdf" Name="Pathways_log.ldf" DiskId="1" Source="\\fileserver\Shared\Databases\Pathways\SystemDBs\Pathways.ldf" Vital="yes"/>
</Component>
And this component must be replaced on a major upgrade. I can only accomplish this so far by setting
<RemoveExistingProducts After="InstallInitialize" />
This breaks the first functionality I need with the settings file. How can I do both?
The problem is that settings.xml shouldn't be installed in the first place, what you really want to do is install something like a 'defaultSettings.xml' and have user-editable settings in a separate location, copying the default to the user/system config in either a post-install configuration step or at first run. If the user modifies the file, and runs a "repair" then it's going to get overwritten anyway, this is the intended behavior of Windows Installer.
If you really want Windows Installer to "leave the file alone" then you're going to need an unmanaged component, i.e. a component with an empty GUID. Such as...
<Component Id="Settings" Guid="" NeverOverwrite="yes">
<File Id="settingsXml" KeyPath="yes" ShortName="SETTINGS.XML" Name="Settings.xml" DiskId="1" Source="\\fileserver\Release\Pathways\Dependencies\Settings\settings.xml" Vital="yes" />
</Component>