使用不同的GUID和Ids'以及互斥條件創建兩個組件:一個用於文件和服務,另一個用於文件。類似這樣的:
<Component Id="SvcComp" Guid="{YOUR-GUID}" SharedDllRefCount="yes">
<Condition> SOME_CONDITION </Condition>
<File Id="SvcFile" Name="Service.exe" Source="Service.exe" Vital="yes" />
<ServiceInstall Id="Svc" Name="Service" DisplayName="Service" Description="Service" Type="ownProcess" Start="auto" ErrorControl="normal" Vital="yes" />
<ServiceControl Id="Svc" Name="Service" Stop="both" Remove="uninstall" Wait="yes" />
</Component>
<Component Id="ExeComp" Guid="{YYOUR-GUID}" SharedDllRefCount="yes" >
<Condition> NOT SOME_CONDITION </Condition>
<File Id="ExeFile" Name="Service.exe" Source="Service.exe" Vital="yes" />
</Component>
您將得到一個LGHT1076警告,因爲組件中的條件是互斥的,所以可能會被禁止。
如果ServiceInstall/@ Start屬性可以設置爲[Property],那將會非常好,因此您仍然可以在不啓動服務的情況下安裝服務。 – Ivan 2017-01-18 10:29:32