Wix自定义操作仅在卸载时

时间:2013-03-19 23:59:27

标签: wix

我在使用Wix卸载服务时只运行自定义操作时遇到问题。

<CustomAction Id='InstallService'
              FileKey='Service.exe'
              ExeCommand='install'
              Execute='immediate'
              Return='check'
              Impersonate='yes'>NOT Installed</CustomAction>

<CustomAction Id='UninstallService'
              FileKey='Service.exe'
              ExeCommand='uninstall'
              Execute='immediate'
              Return='check'
              Impersonate='yes'>Installed AND NOT REINSTALL</CustomAction>

<InstallExecuteSequence>
  <Custom Action='UninstallService' After='StopServices'/>
  <Custom Action='InstallService' Before='StartServices'/>
</InstallExecuteSequence>

这是组件......

  <Component Id="ProductComponent">
    <File Id="MyService.exe"
          Name="MyService.exe"
          Source="..\MyService\bin\Release\MyService.exe"
          Vital="yes"
          KeyPath="yes"
          DiskId="1"/>

    ...

    <ServiceControl Id='ServiceControl'
                    Name='MyService'
                    Start='install'
                    Stop='both'/>
  </Component>

当我运行安装程序时出现错误。查看事件日志,我发现了......

产品:MyService - 错误1721.此Windows Installer程序包存在问题。无法运行此安装所需的程序。请联系您的支持人员或包装供应商。操作:UninstallService,位置:C:\ Program Files(x86)\ MyService \ MyService.exe,命令:uninstall

我也试过这个......

<CustomAction Id='UninstallService'
              FileKey='Service.exe'
              ExeCommand='uninstall'
              Execute='immediate'
              Return='check'
              Impersonate='yes'>Installed AND NOT UPGRADINGPRODUCTCODE</CustomAction>

注意:我使用自定义操作来安装/卸载服务,因为我使用了TopShelf.NET

1 个答案:

答案 0 :(得分:4)

最好的办法是将自定义操作的操作绑定到组件的操作状态。

<InstallExecuteSequence>
   <Custom Action="UninstallService">$ProductComponent=2</Custom>
   <Custom Action="InstallService">$ProductComponent=3</Custom>
</InstallExecuteSequence>

此外,您需要将CustomAction元素作为Execute='deferred'

此外,只有在您创建脚本自定义操作时才允许CustomAction元素中的文本。这似乎不是你在做什么。

添加自定义操作需要相当多的了解。不幸的是第三方平台会force you to use custom actions