I created a Wix setup to install a service. There is my product.wxs :
<?xml version="1.0" encoding="UTF-8"?>
<?define compagny = "MyCompagny"?>
<?define product = "My Service"?>
<?define service = "MyService"?>
<?define version = "!(bind.FileVersion.MyService.exe)"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*"
Name="$(var.product)"
Language="1033"
Version="$(var.version)"
Manufacturer="$(var.compagny)"
UpgradeCode="XXXXXXX">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="MyService.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="CPGNYFOLDER" Name="$(var.compagny)">
<Directory Id="INSTALLFOLDER" Name="$(var.product)" >
<Directory Id="Service_tessdata" Name="tessdata"/>
<Directory Id="Service_x64" Name="x64"/>
<Directory Id="Service_x86" Name="x86"/>
</Directory>
</Directory>
</Directory>
</Directory>
<ComponentGroup Id="InstallComponents">
<Component Id="InstallService" Guid="XXXXXXX" Directory="INSTALLFOLDER">
<File Id="MyService.exe.config"
Name="$(var.service).exe.config"
Source="$(var.MyService.TargetDir)\$(var.service).exe.config"
Vital="yes"/>
<File Id="MyService.exe"
Name="$(var.service).exe"
Source="$(var.MyService.TargetDir)\$(var.service).exe"
Vital="yes"/>
<!-- Install all dll -->
<RemoveFile Id="ALLFILES" Name="*.*" On="both" />
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="$(var.service)"
DisplayName="$(var.product)"
Description=""
Start="auto"
Account="LocalSystem"
ErrorControl="normal" />
<ServiceControl Id="Service_Start" Name="MyService" Start="install" Wait="no" />
<ServiceControl Id="Service_Stop" Name="MyService" Stop="both" Remove="uninstall" Wait="yes" />
</Component>
<!-- Install all directories -->
</ComponentGroup>
<!-- Tell WiX to install the files -->
<Feature Id="ProductFeature" Title="$(var.product)" Level="1">
<ComponentGroupRef Id="InstallComponents" />
</Feature>
</Product>
</Wix>
When I try to install my service, I have error :
Service 'My Service' (MyService) failed to start. Verify that you
have sufficient privileges to start system services
I saw that this error is a generic error. So I ignored it. In my INSTALLFOLDER I have all files. Then I started services.msc and try to start my service. The error is :
Cannot start the service on local computer. Error 193:0xc1
I try to have more details, but I can't find what is the problem. How can I fix this ?
I finally found what was wrong.
In me service properties, I saw that the service path was pointing on MyService.exe.config.
I fixed the problem by adding KeyPath on .exe :
<File Id="MyService.exe"
Name="$(var.service).exe"
Source="$(var.MyService.TargetDir)\$(var.service).exe"
Vital="yes"
KeyPath="yes"/>
Related
Can anybody help me find out why my Windows service won't start.
When I install it with installutil, it works perfectly. I decided to use wix to create an installer for the end user but it won't start.
Here's my code
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="IWErpnextPoll" Manufacturer="IWW" Language="1033" Version="1.0.0.0" UpgradeCode="ccc3c2fe-d20f-45ce-b978-4dc7c84ce6c8">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="IWERPNextPoll_Setup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="IWErpnextPoll" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent">
<File Source="$(var.IWErpnextPoll.TargetPath)" />
<ServiceInstall Id="ServiceInstaller" Name="IWErpnextPoll" Type="ownProcess" Vital="yes" DisplayName="ERPNext2Sage" Description="A background service." Start="auto" Account=".\LocalSystem" ErrorControl="normal" Interactive="no" />
<ServiceControl Id="StartService" Name="IWErpnextPoll" Stop="both" Start="install" Remove="uninstall" Wait="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
The installer throws this error:
Service 'IWErpnextPoll' (IWErpnextPoll) failed to start. Verify that you have sufficient privileges to start system services
I ran the following in the command line:
msiexec /i IWERPNextPoll_Setup /l*v log.txt
but (my untrained eyes) didn't find anything that seemed off in the very very log file.
The service I wrote is my first forray into C#. I'll be very happy to get any pointers.
99.99% of the time this is a problem with the service.
A couple of pro tips.
1) Don't author the ServiceControl element for the first few builds until you know the thing is solid. Test the service after installation.
2) If you do author it, let it sit on the failed to start dialog and start profiling. Run the EXE from a command prompt and see if it is missing dependencies or throws errors. Have lots of logging code in the service to understand what is wrong.
ServiceInstaller is a form of self registration anti pattern. Perhaps you had some code in there doing something like creating an EventSource or a registry key and without it your service is throwing an exception.
Only profiling/debugging will tell for sure.
The answer by #Christopher Painter and the comments on my question led me towards the problem.
The problem was that I did not include my project dependencies in product.wsx. I had to add like so...
...
<Component Id="Serilog.dll">
<File Source="$(var.IWErpnextPoll.TargetDir)Serilog.dll" />
</Component>
<Component Id="Serilog.Settings.AppSettings.dll">
<File Source="$(var.IWErpnextPoll.TargetDir)Serilog.Settings.AppSettings.dll" />
</Component>
<Component Id="Serilog.Sinks.File.dll">
<File Source="$(var.IWErpnextPoll.TargetDir)Serilog.Sinks.File.dll" />
</Component>
<Component Id="RestSharp.dll">
<File Source="$(var.IWErpnextPoll.TargetDir)RestSharp.dll" />
</Component>
...
After this, things started working as expected
Is there any reason that Heat would be causing my windows service to not be added to the registry? I am going through two different commits in my branch and the only difference between the two commits is that the latest one has heat to include dlls from the project that Wix is referencing.
I've looked through the logs using msiexec and /l*v but there isn't anything about the service in there for some reason.
Sorry about the xxx in some of the context of the code as I must remove some of the keywords for security purposes. This is my first time dealing with heat so I am unfamiliar with it and after googling questions about heat I have come to realize that the docs aren't very helpful either.
Product
<?xml version="1.0" encoding="UTF-8"?>
<!-- The name of the product -->
<?define Name = "xxx xxx Agent" ?>
<!-- The manufacturer, for setup package publisher and folder info -->
<?define Manufacturer = "xxx" ?>
<!-- The version number of this setup package-->
<?define Version = "1.0.0" ?>
<!-- UpgradeCode must be unique and not changed once the first version of the program is installed. -->
<?define UpgradeCode = "{145ED92C-BA1B-4257-8791-2337A012EEE7}" ?>
<?if $(var.Platform) = x64?>
<?define bitness = "(64 bit)"?>
<?define Win64 = "yes"?>
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
<?define bitness = "(32 bit)"?>
<?define Win64 = "no"?>
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="$(var.Name) $(var.bitness)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)" Version="$(var.Version)" Language="1033">
<Package InstallerVersion="300" Compressed="yes"/>
<Media Id="1" Cabinet="xxx.xxx.Agent.WindowsService.cab" EmbedCab="yes" />
<MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
<Directory Id="INSTALLFOLDER" Name="$(var.Name)" />
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="$(var.xxx.xxx.Agent.WindowsService.TargetFileName)" Win64="$(var.Win64)" Guid="FD94EF3C-4A0B-4102-AF1E-2A489B4DB7DF">
<RemoveFile Id="ALLFILES" Name="*.*" On="both" />
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="xxx.xxx.Agent.WindowsService"
Account="LocalSystem"
DisplayName="$(var.Name)"
Description="Deployment agent for xxx xxx"
Start="auto"
Interactive="yes"
Vital="yes"
ErrorControl="critical"
Arguments="/start xxx.xxx.Agent.WindowsService"/>
<ServiceControl Id="ServiceUninstaller"
Name="xxx.xxx.Agent.WindowsService"
Stop="uninstall"
Remove="uninstall"
Wait="yes" />-
</Component>
</DirectoryRef>
<Feature Id="MainApplication" Title="Main Application" Level="1">
<ComponentRef Id="$(var.xxx.xxx.Agent.WindowsService.TargetFileName)" />
<ComponentGroupRef Id="HeatGenerated"/>
</Feature>
</Product>
</Wix>
Filter
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.pdb')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.xml')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.dll.config')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.exe')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, 'app.config')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[wix:File/#Source = '$(var.xxx.xxx.xxx.WindowsService.TargetDir)\xxx.xxx.xxx.WindowsService.exe']" use="#Id" />
<xsl:template match="wix:Component[key('service-search', #Id)]" />
<xsl:template match="wix:ComponentRef[key('service-search', #Id)]" />
</xsl:stylesheet>
From the WiX documentation on ServiceInstall, I believe you require a File element:
The service executable installed will point to the KeyPath for the Component. Therefore, you must ensure that the correct executable is either the first child File element under this Component or explicitly mark the appropriate File element as KeyPath='yes'.
So I think you would simply need to add under the service Component:
<File Id="WindowsServiceExe", KeyPath="yes" Source="$(var.xxx.xxx.xxx.WindowsService.TargetDir)\xxx.xxx.xxx.WindowsService.exe" />
Also looking at your transform, I suggest you create separate key names for the "filters" instead of re-using service-search.
I'm using SQLite Database and create installer of WPF application with WIX Toolset. The problem is, The below relative path works fine when I directly run from Visual Studio but does not work when I create installer with WIX and after install this installer run program then it gives fatal error for Database file.
In Project directory I've made a Database folder, in which the database files reside as you can see in below picture:
After creating installer by WIX Toolset, installed files as below:
inventory_control.db file path:
dbConnectionString path:
I've writen code for relative path connection string as under:
Relative Path:
string relativePath = #"Database\inventory_control.db";
string currentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
//string path = currentPath.Substring(0, currentPath.Length - 21);
string path = Path.GetDirectoryName(currentPath);
string absolutePath = System.IO.Path.Combine(path, relativePath);
string dbConnectionString = string.Format("Data Source={0};Version=3;Pooling=True;Max Pool Size=100;", absolutePath);
//string dbConnectionString = "Data Source=inventory_control.db";
sQLiteConnection = new SQLiteConnection(dbConnectionString);
dbConnectionString gives correct current path.
The above relative path works fine when I directly run from Visual Studio but does not work when I create installer with WIX. It gives a fatal error. How to resolve?
WIX File:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><?define Inventory Control_TargetDir=$(var.Inventory Control.TargetDir)?>
<Product Id="f941ba49-4369-44d4-aa0c-b77f20aa41db" Name="Inventory Control" Language="1033" Version="1.0.0.0" Manufacturer="devtros.com" UpgradeCode="ce092371-53cc-4be9-ab5d-c7a2685af970">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<Icon Id="app_icon.ico" SourceFile="$(var.ProjectDir)app_icon.ico" />
<Property Id="ARPPRODUCTION" Value="app_icon.ico" />
<WixVariable Id="WixUIBannerBmp" Value="Images\background.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="Images\background.bmp" />
<WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)License.rtf" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UIRef Id="WixUI_InstallDir" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="Inventory Control" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="ApplicationShortcut" />
<ComponentRef Id="ApplicationShortcutDesktop" />
<ComponentGroupRef Id="Database_files" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Inventory Control">
<Directory Id="Files" Name="Files" />
<Directory Id="Database" Name="Database" />
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="Inventory Control" />
</Directory>
<Directory Id="DesktopFolder" Name="Desktop" />
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="9bd13330-6540-406f-a3a8-d7f7c69ae7f9">
<Shortcut Id="ApplicationStartMenuShortcut" Name="Inventory Control" Description="Inventory Control" Target="[INSTALLFOLDER]Inventory Control.exe" WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Inventory Control" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
<DirectoryRef Id="DesktopFolder">
<Component Id="ApplicationShortcutDesktop" Guid="cde1e030-eb64-49a5-b7b8-400b379c2d1a">
<Shortcut Id="ApplicationDesktopShortcut" Name="Inventory Control" Description="Inventory Control" Target="[INSTALLFOLDER]Inventory Control.exe" WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Inventory Control" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
<Component Id="Inventory_Control.exe" Guid="0a7e7061-201b-4d49-adeb-4449e9c4da3e">
<File Id="Inventory_Control.exe" Name="Inventory Control.exe" Source="$(var.Inventory Control_TargetDir)Inventory Control.exe" />
</Component>
<Component Id="Inventory_Control.exe.config" Guid="28323615-8159-4116-b1ac-e29a70bf2593">
<File Id="Inventory_Control.exe.config" Name="Inventory Control.exe.config" Source="$(var.Inventory Control_TargetDir)Inventory Control.exe.config" />
</Component>
<Component Id="System.Windows.Controls.Input.Toolkit.dll" Guid="7d678201-767a-416b-b645-b2cb7d514893">
<File Id="System.Windows.Controls.Input.Toolkit.dll" Name="System.Windows.Controls.Input.Toolkit.dll" Source="$(var.Inventory Control_TargetDir)System.Windows.Controls.Input.Toolkit.dll" />
</Component>
<Component Id="System.Data.SQLite.dll" Guid="178a5aef-c027-4215-81ae-f148ab6cd472">
<File Id="System.Data.SQLite.dll" Name="System.Data.SQLite.dll" Source="$(var.Inventory Control_TargetDir)System.Data.SQLite.dll" />
</Component>
<Component Id="Zen.Barcode.Core.dll" Guid="20e34fc3-0066-4ffd-b401-518bc1177098">
<File Id="Zen.Barcode.Core.dll" Name="Zen.Barcode.Core.dll" Source="$(var.Inventory Control_TargetDir)Zen.Barcode.Core.dll" />
</Component>
<Component Id="WPFToolkit.dll" Guid="8d974e65-defb-4675-b9e0-ff617e5ab1da">
<File Id="WPFToolkit.dll" Name="WPFToolkit.dll" Source="$(var.Inventory Control_TargetDir)WPFToolkit.dll" />
</Component>
</ComponentGroup>
</Fragment>
<Fragment>
<ComponentGroup Id="Database_files" Directory="Database">
<Component Id="Database_inventory_control.db" Guid="0104b919-0aa9-4dc5-9492-14c474d97cf1">
<File Id="Database_inventory_control.db" Name="inventory_control.db" Source="$(var.Inventory Control_TargetDir)Database\inventory_control.db" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
SQLite.Interop.dll: The file SQLite.Interop.dll needed to be installed along with the rest of the runtime files in order for SQLite
to function properly.
There are two flavors of the file, x86 and x64 format. It is
probably advisable to install both files in their respective folders:
Your installation folder hierarchy - mock-up:
YourBinary.exe
x86\SQLite.Interop.dll
x64\SQLite.Interop.dll
System.Data.SQLite.dll
Etc...
Read-Write DB Location: And then your database should be stored in a writeable path (or you need to make the path writeable for regular users using custom ACL permissioning - which is never a great idea).
Exceptions: Obviously try - catch your database connection, update and access code to detect these kinds of issues.
Folder Confusion: Is there a database file inside the Database folder? It sort of looks like the inventory_control.db file is installed to the main application folder, and not that Database sub-folder?
Maybe that file has been generated by the application.exe in the wrong folder?
Or maybe you have duplicated the file in the main folder for testing purposes?
Hard-Coded Dev-Box Sins?: What does it say in Inventory Control.exe.config?
Are there relevant settings in there that could override your code's values?
Could there be a hard-coded dev-box sin in there?
Path Builder: I assume you have "message boxed" the paths from the application during launch, in order to ensure that they are correct? I like to copy the path and do a Start => Run and paste the path to see that it opens. Press CTRL + C when the message box shows. Paste into Notepad. Extract the path and try it in Start => Run.
string path = currentPath.Substring(0, currentPath.Length - 21);. It is not very robust to hard code the number of characters in the file name to get the parent directory path?
Could you improve it by using Path.GetDirectoryName(currentPath)?
Or maybe even: string dir = currentPath.Substring(0,currentPath.LastIndexOf('\\'));
Attach Debugger & Debug Binaries?: Maybe you could install debug binaries and attach to them for debugging as described here: wix c# app doesn't launch after installing. Just to get a real step-through debugging session.
Path Spaces: That database connection string. Does it need quotes around its path? As in "path with spaces"? You may not have any spaces in the paths for your visual Studio project, but when installed there are spaces in the paths.
This constructs in your source does look weird, why is it necessary?:
<?define Inventory Control_TargetDir=$(var.Inventory Control.TargetDir)?>
Hi I am using Wix to create an Installer that has to write a registry value with the path of the file that the installer copies on the user's system. The problem is that the registry entry should be written in this format
file:///C:/Program Files/....
In the Wix code project I have the INSTALLFOLDER Directory Id which points to
C:\Program Files\....
I am really struggling to convert the latter notation into former. I created a Custom Action hoping to set a property so that I can use that. Following is the code
Custom Action (separate DLL for now, can it be inlined?)
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin CustomAction1");
string origValue = session["INSTALLFOLDER"];
MessageBox.Show(origValue);
string retVal = origValue.Replace("\\", "//");
MessageBox.Show(retVal);
session["Custom_Prop"] = retVal;
return ActionResult.Success;
}
}
And the Product.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SetupProject1" Language="1033" Version="1.2.0.0" Manufacturer="nik" UpgradeCode="4a74ff86-49a9-4011-9794-e1c18077172f">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<InstallExecuteSequence>
<Custom Action='FooAction' Before='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<CustomAction Id='FooAction' BinaryKey='FooBinary' DllEntry='CustomAction1' Execute='immediate'
Return='check'/>
<Binary Id='FooBinary' SourceFile='MyCustomAction.CA.dll'/>
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupProject1" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<Property Id="Custom_Prop" Value="[ProgramFilesFolder]"></Property>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
<Component Id="cmp_Add_Mainfest_To_Registry" Guid="955A3A76-F010-4FCB-BCAF-B297AFD1C05B">
<RegistryKey Root="HKCU" Key="SOFTWARE\company">
<RegistryValue Name="LoadBehavior" Value="3" Type="integer" Action="write" />
<RegistryValue Name="Manifest" Value="[Custom_Prop]" Type="string" Action="write" KeyPath="yes"/>
</RegistryKey>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
However when I run this setup the value written in the registry is the literal string [ProgramFolder] and not its evaluation into either C:\ or C:/
Can someone help?
The reason why my code wasn't working was this line
<InstallExecuteSequence>
<Custom Action='FooAction' Before='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
On changing the value of Before attribute as below made this work
<InstallExecuteSequence>
<Custom Action='FooAction' Before='CostFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
However given my needs were very simple I decided to not have a separate DLL for CustomAction and instead went ahead with a Custom Action in vbscript within the Wix Project. So now the code looks like
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SetupProject1" Language="1033" Version="1.3.1.0" Manufacturer="nik" UpgradeCode="4a74ff86-49a9-4011-9794-e1c18077172f">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<InstallExecuteSequence>
<Custom Action="VBScriptCommand" After="CostFinalize">NOT REMOVE</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<CustomAction Id="VBScriptCommand" Script="vbscript">
<![CDATA[
value = Session.Property("INSTALLFOLDER")
origPath=Session.Property("INSTALLFOLDER")
If Right(webdir, 1) = "\" Then
value = Left(value, Len(value) - 1)
End If
Session.Property("SOME_PROPERTY") = Replace(origPath,"\","//")
]]>
</CustomAction>
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupProject1" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<Property Id="Custom_Prop" Value="[ProgramFilesFolder]"></Property>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="cmp_Add_Mainfest_To_Registry" Guid="955A3A76-F010-4FCB-BCAF-B297AFD1C05B">
<RegistryKey Root="HKCU" Key="SOFTWARE\something">
<RegistryValue Name="LoadBehavior" Value="3" Type="integer" Action="write" />
<!--<RegistryValue Name="Manifest" Value="[#FILE_VstoManifest]|vstolocal" Type="string" Action="write" />-->
<RegistryValue Name="Manifest" Value="file:///[SOME_PROPERTY]" Type="string" Action="write" KeyPath="yes"/>
</RegistryKey>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Perhaps the purists won't like this but why use a Shot gun to kill a fly?
Nikhil helped me with his answer. My installs all go to subfolders so when I find an old component I need the parent folder for install, so I came here for an answer.
Combined with this get parent
I found how to get the parent folder since I have a known fixed install sub path.
<!-- Set INSTALLFOLDER from SERVERINSTALLFOLDER without the \Server\ -->
<CustomAction Id="VBScriptInstallFolderFromFoundServer" Script="vbscript">
<![CDATA[
pathvalue = Session.Property("SERVERINSTALLFOLDER")
if pathvalue <> "" Then
Session.Property("INSTALLFOLDER") = Left(pathvalue,Len(pathvalue)-Len("\Server\"))
End If
]]>
</CustomAction>
Combined with Locate Installation directory of another product
<Property Id="SERVERINSTALLFOLDER">
<!-- Id="C_SERVER_SERVERHOST.EXE" Guid="{xxx GUID OF my exe component xxx}" -->
<ComponentSearch Id="ServerComponentSearch" Type="file" Guid="{xxx GUID OF my exe component xxx}">
<DirectorySearch Id="ServerComponentDirectorySearch" Depth="0" AssignToProperty="yes" />
</ComponentSearch>
</Property>
And with Wix remember property pattern
storing the INSTALLFOLDER path in registry.
I can now update old, or install new getting the correct install path of previous install as suggestion.
Not quite the answer to the question but as I was lead here to get this, my answer will help others on the same path...
My InstallUISequence and InstallExecuteSequence :
<!-- Save INSTALLFOLDER parameter to CMDLINE_INSTALLFOLDER -->
<Custom Action='SaveCmdLineValue' Before='AppSearch' />
<!-- Set INSTALLFOLDER from SERVERINSTALLFOLDER without the \Server\ -->
<Custom Action="VBScriptInstallFolderFromFoundServer" After="AppSearch">
SERVERINSTALLFOLDER
</Custom>
<!-- Set INSTALLFOLDER from parameter CMDLINE_INSTALLFOLDER -->
<Custom Action='SetFromCmdLineValue' After='VBScriptInstallFolderFromFoundServer'>
CMDLINE_INSTALLFOLDER
</Custom>
And lastly... in Product I to refer to the Fragment I put these in:
<!-- Install to previous install path From parameter, OR from found installation OR from registry -->
<CustomActionRef Id='SaveCmdLineValue' />
<PropertyRef Id='INSTALLFOLDER'/><!-- include Fragment -->
<PropertyRef Id='SERVERINSTALLFOLDER'/><!-- include Fragment -->
<CustomActionRef Id='VBScriptInstallFolderFromFoundServer' /><!-- include Fragment -->
I have 2 projects in my soliution:
1). Custom action class (CustomAction)
2). Wix setup project (TestSetup)
There is CustomAction.cs in CustomAction project:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
File.Create(#"c:\installed.txt");
return ActionResult.Success;
}
}
}
Product.wxs:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="TestSetup" Language="1033" Version="1.0.0.0" Manufacturer="SB2"
UpgradeCode="39d922d3-a3f5-4207-b905-124615dda25d">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes"/>
<Feature Id="ProductFeature" Title="TestSetup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<InstallExecuteSequence>
<Custom Action="CustomAction" Before="InstallFinalize" />
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="TestSetup" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="result.rtf">
<File Id="result.rtf" Source="result.rtf" KeyPath="yes" Checksum="yes" />
</Component>
</ComponentGroup>
</Fragment>
<Fragment>
<CustomAction Id='CustomAction' BinaryKey='CustomAction.CA' DllEntry='CustomAction' />
<Binary Id='CustomAction.CA' SourceFile='..\CustomAction\bin\Debug\CustomAction.CA.dll' />
</Fragment>
</Wix>
Setup project buils without problems, but when I'm trying to run it I get a error message:
"There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor"
I think it's because of incorrect binary source file value.
Would you to show how to fix it?
The problem is that your CustomAction method name "CustomAction1" does not match with the "DLLEntry" value which you have mentioned (DllEntry='CustomAction'). You are missing "1" :)
<CustomAction Id='CustomAction' BinaryKey='CustomAction.CA' DllEntry='CustomAction' />
You should write like this:-
<CustomAction Id='CustomAction' BinaryKey='CustomAction.CA' DllEntry='CustomAction1' />
where CustomAction1 is your CustomAction Name..