我编写了一个示例WiX项目,其中我尝试在安装时保存项目文件,然后在卸载过程中删除这些文件。我已经编写了自定义操作来实现此目的。以下是代码。
此处,UninstallCustomAction是删除安装目录的自定义操作。这是一个延迟操作,我试图使用SetCustomActionDataValue自定义操作将installFolder路径传递给它。出于某种原因,我无法在会话的CustomActionData中访问这些变量。我在这里缺少什么?
<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;
}
答案 0 :(得分:2)
不需要自定义操作:在WixUtilExtension中使用RemoveFoldersEx。