【问题标题】:Wix Custom Action only on uninstall仅在卸载时使用 Wix 自定义操作
【发布时间】:2013-03-08 21:55:59
【问题描述】:

我无法让自定义操作仅在我使用 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 安装程序包有问题。无法运行完成此安装所需的程序。请联系您的支持人员或软件包供应商。操作:UninstallService,位置:C:\Program Files (x86)\MyService\MyService.exe,命令:卸载

我也试过这个...

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

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

【问题讨论】:

    标签: wix


    【解决方案1】:

    最好的办法是将自定义操作的操作与组件的操作状态联系起来。

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

    另外,您需要将 CustomAction 元素设为 Execute='deferred'

    此外,CustomAction 元素中的文本仅在您创建脚本自定义操作时才允许使用。看来你不是这样的。

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

    【讨论】:

    • 太棒了,感谢您为我指明了正确的方向。实际上,我最终使用 ?ProductComponent=3 进行卸载,使用 $ProductComponent=3 进行安装,现在它可以正常工作了。
    • 使用 ?ProductComponent=3 意味着即使没有删除组件也会触发卸载。例如,在修复期间,我希望您的卸载自定义操作会被调用。可能不是目标。 :)
    • 当我尝试 $ProductComponent=2 时不起作用。所以我四处寻找并找到了?限定词
    • 我已将其改回 $ProductComponent=2,现在看起来还不错。我不确定之前发生了什么,也许有些不合时宜。
    • 在哪里可以查找这些州? 2 = 卸载、3 = 安装和 1 = 重新安装?
    猜你喜欢
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 2019-04-19
    • 2012-03-21
    • 1970-01-01
    • 2013-06-29
    • 2011-08-10
    相关资源
    最近更新 更多