0

我有以下 Wix 片段,它根据是安装还是卸载调用两个自定义操作之一:

<?xml version="1.0" encoding="UTF-8" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?include $(sys.CURRENTDIR)\Config.wxi?>
  <Fragment>
    <CustomAction Id="caSetPropertyForInstall" Property="caRegisterDriver" Value="DeviceId=$(var.DriverId);DeviceName=$(var.ChooserName)" />
    <CustomAction Id="caSetPropertyForUninstall" Property="caUnregisterDriver" Value="DeviceId=$(var.DriverId);DeviceName=$(var.ChooserName)" />
    <Binary Id="DriverRegCA" SourceFile="$(var.ASCOM.Wix.CustomActions.TargetDir)\$(var.ASCOM.Wix.CustomActions.TargetName).CA.dll" />
    <CustomAction Id="caRegisterDriver" BinaryKey="DriverRegCA" DllEntry="RegisterAscomDriver" Execute="deferred" Return="check" />
    <CustomAction Id="caUnregisterDriver" BinaryKey="DriverRegCA" DllEntry="UnregisterAscomDriver" Execute="immediate" Return="ignore" />
    <InstallExecuteSequence>
      <Custom Action="caSetPropertyForInstall" Before="caRegisterDriver" />
      <Custom Action="caSetPropertyForUninstall" Before="caUnregisterDriver" />

      <!-- Execute during install -->
      <Custom Action="caRegisterDriver" Before="InstallFinalize">NOT Installed</Custom>

      <!-- Execute during uninstall -->
      <Custom Action="caUnregisterDriver" Before="RemoveFiles">REMOVE ~= "ALL"</Custom>
    </InstallExecuteSequence>
  </Fragment>
</Wix>

安装 CA 按预期工作。我在操作 Id=caSetpropertyForInstall 中设置了一些属性,然后操作 caRegisterDriver 调用我的 C# 托管自定义操作。C# 代码查询自定义操作属性,如下所示:

var deviceId = session.CustomActionData["DeviceId"];
var deviceName = session.CustomActionData["DeviceName"];
Diagnostics.TraceInfo("Property DeviceId = [{0}]", deviceId);
Diagnostics.TraceInfo("Property DeviceName = [{0}]", deviceName);

无论是安装还是卸载,都使用相同的 C# 方法,并且如前所述,这在安装阶段有效。

我的问题是在卸载阶段,我收到一个异常:

1 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ===== TiGra.Diagnostics 已初始化:默认 TraceLevel = 警告 =====
2 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[信息]:开始 UnregisterAscomDriver 自定义操作
3 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[错误]:查询安装程序属性时出错
4 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[错误]: System.Collections.Generic.KeyNotFoundException: 给定的键不在字典中.
5 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 System.ThrowHelper.ThrowKeyNotFoundException()
6 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 System.Collections.Generic.Dictionary`2.get_Item(TKey 键)
7 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(字符串键)
8 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 ASCOM.Wix.CustomActions.CustomActions.CreateAscomDeviceFromSessionProperties(IInstallerPropertyProvider 会话)
9 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[错误]:UnregisterAscomDriver 失败:System.Collections.Generic.KeyNotFoundException:给定的密钥不存在在字典里。
10 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 System.ThrowHelper.ThrowKeyNotFoundException()
11 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 System.Collections.Generic.Dictionary`2.get_Item(TKey 键)
12 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(字符串键)
13 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 ASCOM.Wix.CustomActions.CustomActions.CreateAscomDeviceFromSessionProperties(IInstallerPropertyProvider 会话)
14 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe 在 ASCOM.Wix.CustomActions.CustomActions.UnregisterAscomDriver(会话会话)

我看不出我处理安装和卸载的方式有什么不同,所以我很困惑为什么会这样。我错过了一些明显的东西吗?

4

1 回答 1

3

您将自定义操作“caUnregisterDriver”安排为立即执行而不是延迟执行。它没有要反序列化到集合中的 CustomActionData 属性。

顺便说一句,我也没有看到回滚和提交自定义操作,所以我也会担心这一点。

于 2013-01-23T03:37:38.060 回答