0
votes

I have written a sample WiX project wherein I am trying to save project files while installing and later delete these files during the uninstall process. I have written custom actions to achieve this. Below is the code.

Here, UninstallCustomAction is the custom action to delete the install directory. This is a deferred action, and I am trying to pass installFolder path to it using SetCustomActionDataValue custom action. For some reason, I am unable to access these variable in the sessions's CustomActionData. What am I missing here?

<CustomAction Id="SetCustomActionDataValue"
              Return="check"
              Property="Itp.Configurator.WixCustomAction"
              Value="InstallFolder=[INSTALLFOLDER]" />


<CustomAction Id="UninstallCustomAction"
              Return="check"
              Execute="deferred"
              BinaryKey="DTD.LCTOnline.Wix.CustomActions.CA.dll"
              DllEntry="UninstallCustomAction"
              Impersonate="no"
              HideTarget="no"/>
<InstallExecuteSequence>
    <Custom Action="SetCustomActionDataValue"
            Before="UninstallCustomAction"></Custom>
    <Custom Action="UninstallCustomAction"
            Before="InstallFinalize">Installed OR UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>


[CustomAction]
public static ActionResult UninstallCustomAction(Session session)
{
    try
    {
        System.Diagnostics.Debugger.Launch();
        session.Log("Begin Remove Files");
        Directory.Delete(path,true);
        session.Log("End Remove Files");

    }
    catch (Exception ex)
    {
        session.Log("ERROR in deleting Files", ex.ToString());
        return ActionResult.Failure;
    }
    return ActionResult.Success;
}
1

1 Answers

2
votes

No custom action is needed: Use RemoveFoldersEx in WixUtilExtension.