Let me start by saying that I don’t enjoy working with Wix and that I am a total Wix beginner. I get virtual headaches every time I have to deal with Wix. The most recent head pain came from the requirement to remove a certificate from Windows’ certificate store only after removal of all dependent websites. Just rely on Wix’s Component reference count, no? Well, as I expected, nothing worked the first time.
My understanding of reference count was that it depended on the KeyPath attribute within the component and that the flag could be set on either a registry or a file. I had 2 .wxs files for the 2 web applications, and each contained a Component section with the same GUID and KeyPath.
My first attempt was to simply rely on Component element’s KeyPath attribute. It didn’t work, unfortunately, probably because dir_3 values for the 2 apps were different.
<Directory Id='dir_1' Name='xxx'>
<Directory Id='dir_2' Name='xxx'>
<Directory Id='dir_3' Name='xxx'>
<Directory Id='dir_public' Name='xxx'>
<Component Id='InstallCertificate' Guid='xxx' DiskId='1' KeyPath='yes'>
<iis:Certificate Id='cert' ... />
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
So I proceeded to add a registry value to coordinate the certificate uninstall. I tried many combinations of elements and attributes, but none of them worked. The registry key/value was created but stuck around after uninstallation.
<Directory Id='dir_1' Name='xxx'>
<Directory Id='dir_2' Name='xxx'>
<Directory Id='dir_3' Name='xxx'>
<Directory Id='dir_public' Name='xxx'>
<Component Id='InstallCertificate' Guid='xxx' DiskId='1'>
<RegistryKey Id='CertificateKeyPath' Action='create' Root='HKLM' Key='xxx'>
<RegistryValue Id='CertificateKeyValue' Value='xxx' Type='string' KeyPath='yes' />
</RegistryKey>
<iis:Certificate Id='cert' ... />
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
I was about to give up and leave the stuck certificate in peace, that’s when I gave it one last shot and moved the Component up to the common directory level. This change must have aligned the stars, ’cause it worked!
<Directory Id='dir_1' Name='xxx'>
<Directory Id='dir_2' Name='xxx'>
<Component Id='InstallCertificate' Guid='xxx' DiskId='1' KeyPath='yes'>
<iis:Certificate Id='cert' ... />
</Component>
<Directory Id='dir_3' Name='xxx'>
<Directory Id='dir_public' Name='xxx'>
...
</Directory>
</Directory>
</Directory>
</Directory>
I know little Wix kung fu, but I can guess why moving the component up the directory hierarchy worked. What I don’t understand is why the registry approach didn’t work. Any Wix master out there who can enlighten me?
I use Wix v3.0.