卸载时的CustomAction,其中设置了INSTALLLOCATION

时间:2017-02-01 02:26:05

标签: c# wix

我有一个Windows服务,当它运行时,它会在Windows服务的安装位置记录嵌套日志文件。我正在尝试编写一个自定义操作,仅在卸载时删除所述文件。但是,当它运行时,我得到一个“INSTALLLOCATION是一个无效的目录”错误。我假设我需要在“After =”?“子句中运行自定义操作时更改,但我不确定它应该是什么。

这是.wxs文件的当前代码

<Binary Id="CustomActionEXE" SourceFile="$(var.MyApp.TargetDir)MyApp.CA.dll" />
<CustomAction Id="RemoveLogFilesCA" BinaryKey="CustomActionEXE" DllEntry="RemoveLogFiles" Execute="immediate" Return="check"/>
<InstallExecuteSequence>
  <Custom Action="RemoveLogFilesCA" After="RemoveFiles">
    (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
  </Custom>
</InstallExecuteSequence>

自定义操作代码

public class CustomActions
{
    [CustomAction]
    public static ActionResult RemoveLogFiles(Session session)
    {
        // Error here: "INSTALLLOCATION is an invalid directory", value not set when the custom action is being executed After="RemoveFiles"
        //string installLocation = session.GetTargetPath("INSTALLLOCATION");
        return ActionResult.Success;
    }
}

1 个答案:

答案 0 :(得分:1)

首先我建议日志文件是用户数据,1)不应该在卸载时删除,2)不应该保存在ProgramFilesFolder下。 ProgramData会是一个更好的地方。

如果您必须递归删除这些文件,请不要使用您自己的CA重新发明轮子。请改用RemoveFolderEx Element (Util Extension)