Wix自定义操作属性 - 为什么这不起作用?

时间:2013-01-23 03:10:10

标签: wix custom-action

我有以下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 Initialized: Default TraceLevel = Warning =====
2 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Info]: Begin UnregisterAscomDriver custom action
3 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Error]: Error while querying installer properties
4 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Error]: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
5 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.ThrowHelper.ThrowKeyNotFoundException()
6 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
7 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(String key)
8 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at ASCOM.Wix.CustomActions.CustomActions.CreateAscomDeviceFromSessionProperties(IInstallerPropertyProvider session)
9 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Error]: UnregisterAscomDriver failed: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
10 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.ThrowHelper.ThrowKeyNotFoundException()
11 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
12 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(String key)
13 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at ASCOM.Wix.CustomActions.CustomActions.CreateAscomDeviceFromSessionProperties(IInstallerPropertyProvider session)
14 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at ASCOM.Wix.CustomActions.CustomActions.UnregisterAscomDriver(Session session)

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

1 个答案:

答案 0 :(得分:3)

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

BTW我也看不到回滚和提交自定义操作,所以我也会关注它。