Tuesday, June 22, 2010

WIX Patch: replace keypath and restart service

I need to create a small update (patch) for my application. I have large application with about 2000 of files. Source project comprises 13 wxs files. A file list is generated by the "heat" command. So, each file is represented as a single component and become a key path (key file) for the component.
During the update I want to replace one dll which is used by a service. So, I have to stop the service, replace the dll and start the service.
After few days of investigation I found out the following:
There are at least two options for patch creation using WIX:
1. Using Purely WiX
2. Using Patch Creation Properties

I prefered the first one.

Commands for the patch creation are discribed in the link above. I did the following:
1. Modify the component for the file to be replaced:
originally was:
<Component Id="cmp1000" Guid="GUID">
<File Id="file1000" KeyPath="yes" Source="$(var.Root)\File.dll" />
</Component>

change to:
<Component Id="cmp1000" Guid="GUID">
<ServiceControl Id='StopServicePatch' Name='ServiceName' Stop='install'/>
<File Id="file1000" KeyPath="yes" Source="{new path}\File.dll" />
<ServiceControl Id='StartServicePatch' Name='ServiceName' Start='install'/>
</Component>
The source file path has been changed as well as ServiceControl actions are added.
2. Build two msi files with the same name
3. Create msp patch file

But if you now run the patch by double clicking on the .msp file, it does not work as expected - it runs UI and asks to choose option for the original application - modify, repair or remove.
4. To install the patch run the following command line:
msiexec /p patch.msp LIMITUI=1 REINSTALLMODE=emus

setting the LIMITUI property restricts UI and the patch is installed without displaying any dialog windows.
the REINSTALLMODE specifies type of reinstallation to be performed. By default the REINSTALLMODE is "omus", but in this case my dll is not replaced as it has the same version number. So, I changed property to "emus" and now the dll is replaced by the patch.

in the log file of the patch installation I see the file is repalced:
Patch Modified Files List:
MSI (s) (A4:64) [15:38:51:275]: File = file1000: Final State = Install
...
File: C:\Program Files (x86)\MyApp\File.dll; Overwrite; Won't patch; Existing file is of an equal version

No comments:

Post a Comment