【发布时间】:2023-03-22 20:08:01
【问题描述】:
我正在做 WIX MSI 静默安装,如果自定义操作失败,还有一些自定义操作在检查之间如何回滚或结束 msi 的静默安装过程??我正在复制文件并使用启动 Windows 服务Wix 安装。当自定义操作失败时,我如何停止创建目录和启动 Windows 服务??
[CustomAction]
public static ActionResult PrerequisiteCheck(Session session)
{
if (Status.IsServiceAvailable && Status.IsPrinter)
{
return ActionResult.Success;
}
else
{
//Stop Installer
return ActionResult.Failure;
}
}
<CustomAction Id="CheckPrerequiste" BinaryKey="BIN_CustomAction" DllEntry="CheckPrerequiste" Return="ignore" Execute="immediate" />
<InstallExecuteSequence> <Custom Action="CA_PrerequisiteCheck" After="InstallExecute" > </Custom>
</InstallExecuteSequence>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="Service">
<Component Id="WindowsService" Guid="AA34D3C1-26F1-4A7E-A226-1AB01501C67C">
<File Id="00690A65EA1A3EFEB7607285DBA0C8C5" KeyPath="yes" Source="WindowsService.Svc.exe" />
<ServiceInstall Id="Service" Name="Service" DisplayName="Windows Service" Description="Windows Service" Start="auto" ErrorControl="normal" Type="ownProcess" />
<ServiceControl Id="sc_Service" Name="Service" Stop="both" Remove="uninstall" Wait="yes" />
<Component Id="WindowsSvcexe" Guid="06ABF18B-DEDE-4D98-AF9F-8384539A6BC3"> <File Id="49215CE1A25380930C771772AD14519B" KeyPath="yes" Source="WindowsService.Svc.exe.config" /> </Component> </Component>
</Directory>
</Directory>
</Directory>
【问题讨论】:
-
我个人认为让整个安装失败并回滚然后尝试排除故障并修复导致其失败的自定义操作的问题是最简单的。现在,如果您正在检查先决条件,也许您可以为需要先决条件的组件创建一个功能,并在它们不满足先决条件时禁用它。