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

时间:2015-07-31 07:40:54

标签: wix windows-installer

我正在使用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'/>

1 个答案:

答案 0 :(得分:3)

这不起作用,因为文件和文件夹未在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>