I needed to add a CustomAction that removed the native image from the GAC. To do this I came across more slightly odd behaviour from the windows install platform so I thought I’d write a blog entry about it.

<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /> /o:p

At first glance creating an uninstall action looks dead easy. Just create a custom action that does the opposite of what you did on install. In the case of ngen this is just adding an extra /delete switch, an absolute cinch! The syntax for the remove custom action is shown below. Note the use of the Return property to ignore the result, it possible that the action will fail because someone has removed the native image by hand; using the Return property this way will stop uninstallation failing if this happens.


<CustomAction Id=“Test.exeFileRemoveNGen” ExeCommand=‘”[WindowsFolder]Microsoft.NET\Framework\v1.1.4322\ngen.exe” /delete “[#DataPharm.PharmaNet.Logging.dllFile]“’ Directory=“InstallDir”  Return=“ignore” />


Then pop a reference to this new custom action in the “InstallExecuteSequence” section of the install script. Job’s a good’un. Or so I thought.


An “normal” MSI produced by wix will have the following actions in its InstallExecutionSquence table There are many ways to added and remove stuff from this list, if you don’t do any of them this is what will be produced.


ValidateProductID                      700/o:p

CostInitialize                              800/o:p

FileCost                                    900/o:p

CostFinalize                              1000/o:p

InstallValidate                            1400/o:p

InstallInitialize                            1500/o:p

ProcessComponents                  1600/o:p

UnpublishComponents                1700/o:p

MsiUnpublishAssemblies            1750/o:p

UnpublishFeatures                     1800/o:p

RemoveShortcuts                       3200/o:p

RemoveFiles                              3500/o:p

InstallFiles                                 4000/o:p

CreateShortcuts             4500/o:p

RegisterUser                             6000/o:p

RegisterProduct                         6100/o:p

MsiPublishAssemblies               6250/o:p

PublishFeatures             6300/o:p

PublishProduct                          6400/o:p

InstallFinalize                            6600


The interesting thing is an install whips though all of them on when both installation and uninstalling. On installation it starts with the lowest number and works forward, on uninstallation it starts with the highest number and works backwards. This is cool most of the time because most actions done by the installer are reversible, for example the installer knows that if you try and remover a file before you install it, it’s not a big deal.


When you add in custom actions you add extra entries to this list; which creates a problem. Most CustomActions will have problems being run both on install and uninstall. To get round this you have to give your CustomAction a condition so it will only be run on installation or installation. You can find out load of good information about condition at the Conditional Statement Syntax section of the windows installer documentation. In case you’d rather not read though that and figure it out for you’re self I’ve given the systax below.


A condition for a custom action that should only be run at install has the following format:



A condition for a custom action that should only be run at uninstall has the following format:



This condition should be placed inside the Custom tag that controls when the CustomAction is executed. This gives our example wix file the following format:



<Custom Action=“Test.exeFileRemoveNGen” After=“MsiUnpublishAssemblies”>$Test.exeComponent=2</Custom>/o:p

<Custom Action=“Test.exeFileNGen” After=“InstallFinalize”>$Test.exeComponent&gt;2</Custom>/o:p



The full wix sources file is available here. Again it should compile but will not link without an available Test.exe assembly.


Feedback was imported from my only blog engine, it’s no longer possible to post feedback here.

re: CustomActions and uninstalls - Badri

Hi i am doing upgrade coding using Cadle and light i.e. Wix I am Getting Install Finalize return 3. What Might the causes

re: CustomActions and uninstalls - Robert Pickering

Sorry, I have no idea. You probably want to ask the wix mailing list. You will probably need to provide more details.


re: CustomActions and uninstalls - Warren

Thankyou for this, it helps me out. With a few tweaks, your code works with the new version. http://schemas.microsoft.com/wix/2006/wi

re: CustomActions and uninstalls - Pablo

Great stuff!
I have a custom action which is not closely related to a component (it only sets some properties); which component should I use in the condition? Is just picking anyone OK?
Thanks for sharing,

re: CustomActions and uninstalls - Sathish

I need clear unstalled wile unstalled the application services running…While start the unstallation error getting because the application services still running. I need to unstalled the application with custom action needed with stop the services…