条件 属性 WIX 失败导致整个 MSI 作业失败

Condition property failure in WIX failing entire MSI job

我正在使用 WIX 为 C# 服务创建 MSI 安装程序。 MSI 做 3 个工作:

a) 将解决方案文件从 bin 复制到特定位置。

b) 创建一个文件夹,服务在其中写入日志。

c) 如果该服务以前不存在,请在机器上安装该服务。

希望这些以类似的顺序执行。但是,当检查服务是否已安装的条件失败时,上一步似乎没有执行,即复制和创建步骤也失败了。

这是代码片段。

<Directory Id="TARGETDIR" Name="SourceDir">      
  <!--Creating folder hierarchy for storing project solution files;  reference defined in fragments-->
  <Directory Id="ProgramFilesFolder" Name="PFiles"/>

  <!--Creating folder hierarchy for storing logs; reference defined in fragments-->
  <Directory Id="LOGS" Name="Logs"/>
</Directory>

<InstallExecuteSequence>
  <LaunchConditions After='AppSearch' />
  <Custom Action='CMDInstallService' Before='InstallFinalize'></Custom>
</InstallExecuteSequence>

<Property Id="MYSERVICE">
  <RegistrySearch Id="SERVICE_CHECK" Root="HKLM" Name="Install" Type="raw"
                      Key="SYSTEM\CurrentControlSet\services\Service"/>
</Property>

<Condition Message="Service is already installed on your system">
  <![CDATA[Installed OR MYSERVICE]]>
</Condition>

<CustomAction
  Id='CMDInstallService' Directory='PROJECT_INSTALL' Execute='deferred' Impersonate='no'
  ExeCommand='[SystemFolder]cmd.exe /K &quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe Service.exe&quot;'
  Return ='check'/>

这将不起作用,因为文件和文件夹未在 InstallFinalize 之前提交。要安装服务,您应该使用以下命令:

<Component Id="Component_WinService" Directory="Directory_WindowsService" Guid="*">

    <File Id="File_WindowsService" KeyPath="yes"
                Source="WindowsService.exe" />

    <ServiceInstall Id="ServiceInstall_WindowsService"
                                    Type="ownProcess"
                                    Vital="yes"
                                    Name="My Windows service"
                                    Description="Windows service."
                                    Start="auto"
                                    Account="LocalSystem"
                                    ErrorControl="ignore"
                                    Interactive="no" 
                                    />

    <ServiceControl Id="ServiceControl_WindowsService"
                                    Start="install"
                                    Stop="both"
                                    Remove="uninstall"
                                    Name="My Windows Service" 
                                    Wait="no"
                                    />

</Component>