I have an installer solution in visual studio that contains the C# windows application bootstrapper, and two msi projects. I want to schedule a custom action for one of two msis to run during the uninstall sequence - so I first added a CustomActions projects to the same solution (called "CustomActions"), which has the CustomAction.cs file that defines the custom function to be scheduled. This function should just write something to the log file for now:
namespace CustomActions
{
public class CustomActions
{
[CustomAction]
public static ActionResult UninstallSecondaryMsi(Session session)
{
session.Log("Begin CustomAction1");
/* Search for ProductCode of the secondary msi here; run msiexec to uninstall it */
return ActionResult.Success;
}
}
I added the CustomActions project reference to my msi project, and then added the following to my product.wxs:
<!-- Custom Actions -->
<Fragment>
<Binary Id="customActionDLL" SourceFile="$(var.CustomActions.TargetDir)\CustomActions.CA.dll" />
<CustomAction Id="CustomAction_GetRegistryKey"
BinaryKey="customActionDLL"
DllEntry="UninstallSecondaryMsi"
Execute="immediate"
Return="check" />
<InstallExecuteSequence>
<Custom Action="CustomAction_GetRegistryKey"
After="InstallFinalize"></Custom>
</InstallExecuteSequence>
</Fragment>
I ran the bootstrapper that triggers the msi, but the "Begin CustomAction1" string was not in the log file. I thought maybe it wasn't just logging properly, but when I viewed the generated msi with Orca.exe, I saw that my custom action was not scheduled under the CustomActions table or the InstallExecuteSequence table.
Is there something that I'm missing here? I also guessed that the path to the CustomActions.CA.dll wasn't correct and tried hard-coding the path to the DLL, but that did not work either. Any help would be greatly appreciated, thanks in advance!
Ah, my Custom Actions elements were in the main Product.wxs file but in a different fragment, and that fragment wasn't getting referred to anywhere. I put in a ComponentGroup under that Fragment and made a reference to its ID under the Feature element - and it worked. My apologies.