4

我无法让自定义操作仅在我使用 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

4

1 回答 1

4

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

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

此外,您将需要您的CustomAction元素是Execute='deferred'.

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

添加自定义操作需要相当多的理解。不幸的是,第 3 方平台会强迫您使用自定义操作

于 2013-03-20T03:41:26.447 回答