我在让自定义操作仅在使用 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>
Run Code Online (Sandbox Code Playgroud)
这是组件...
<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>
Run Code Online (Sandbox Code Playgroud)
当我运行安装程序时,出现错误。查看事件日志我发现这个......
产品: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>
Run Code Online (Sandbox Code Playgroud)
注意:我使用自定义操作来安装/卸载服务,因为我使用了TopShelf.NET
最好的选择是将自定义操作的操作与组件的操作状态联系起来。
<InstallExecuteSequence>
<Custom Action="UninstallService">$ProductComponent=2</Custom>
<Custom Action="InstallService">$ProductComponent=3</Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)
另外,你需要你的CustomAction元素是Execute='deferred'.
另外,文本中CustomAction仅当您创建脚本自定义操作时才允许在元素中使用文本。看来你不是这么做的。
添加自定义操作需要相当多的理解。不幸的是,第三方平台会强迫您使用自定义操作。