2009-08-12 55 views
5

如何在WiX中安裝帶有一些附加文件的服務,並定義實際的服務EXE文件是什麼文件?使用WiX安裝多文件NT服務(2.0)

場景:我這只是一個單一的EXE文件的服務,並將其安裝在維克斯Windows NT服務使用此代碼:

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'> 
    <File Id='InstallMyServiceEXEFile' LongName='MyService.exe' 
     Name='MyServ.exe' src='MyService/bin/release/MyService.exe' KeyPath='yes'/> 
    <ServiceInstall Id='InstallMyService' Name='MyService' Description='My Service' 
     ErrorControl='normal' Start='auto' Type='ownProcess' Vital='yes' /> 
    <ServiceControl Id='UninstallMyService' Name='MyService' Remove='uninstall' 
     Wait='yes' /> 
</Component> 
<Component Id='RunMyServiceComponent' Guid='.......'> 
    <ServiceControl Id='RunMyService' Name='MyService' Start='install' 
     Stop='uninstall' Wait='no' /> 
</Component> 

,我有一個功能,那麼這將允許安裝並可選擇啓動此服務。

現在,我的問題是 - 現在我的服務增長了,單個EXE不再是單個EXE - 它是多個文件,EXE,DLL和一些支持文件。

但是,我現在怎麼安裝?

我想有一個component,我的所有文件

<Component Id="MyService" Guid="......" DiskId="1"> 
    <File Id="fileMyService_framework_dll" LongName="Framework.dll" 
     Name="Framewrk.DLL" src="MyService\Framework.dll" /> 
    <File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll" 
     Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" /> 
    <File Id="fileMyService_helpers_dll" LongName="Helpers.dll" 
     Name="Helpers.DLL" src="MyService\Helpers.dll" /> 
    <File Id="fileMyService_exe" LongName="MyService.exe" 
     Name="MySrv.EXE" src="MyService\MyService.exe" /> 
</Component> 

首先,我想只是添加則ServiceInstall和的ServiceControl標籤這個組件:

<Component Id="MyService" Guid="......" DiskId="1"> 
    <File Id="fileMyService_framework_dll" LongName="Framework.dll" 
     Name="Framewrk.DLL" src="MyService\Framework.dll" /> 
    <File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll" 
     Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" /> 
    <File Id="fileMyService_helpers_dll" LongName="Helpers.dll" 
     Name="Helpers.DLL" src="MyService\Helpers.dll" /> 
    <File Id="fileMyService_exe" LongName="MyService.exe" 
     Name="MySrv.EXE" src="MyService\MyService.exe" /> 
    <ServiceInstall Id='InstallMyService' Name='MyService' 
     Description='My Service' ErrorControl='normal' Start='auto' 
     Type='ownProcess' Vital='yes' /> 
    <ServiceControl Id='UninstallMyService' Name='MyService' 
     Remove='uninstall' Wait='yes' /> 
</Component> 

但後來我的「框架。 DLL「被設置爲創建服務的源路徑........

所以我想創建第二個組件來實際安裝服務,使用ServiceInstall ,我只是使用FileRef引用該服務EXE文件 - 但似乎並不存在(至少在Wix2中)。

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'> 
    <FileRef Id='fileMyService_exe' KeyPath='yes'/> 
    <ServiceInstall Id='InstallMyService' Name='MyService' 
     Description='My Service' ErrorControl='normal' Start='auto' 
     Type='ownProcess' Vital='yes' /> 
    <ServiceControl Id='UninstallMyService' Name='MyService' 
     Remove='uninstall' Wait='yes' /> 
</Component> 

所以 - 什麼是貧窮的WiX筆者所要做的安裝所有必要的文件,並仍然得到NT Service安裝拿起從文件中的組件列表中選擇正確的EXE文件(不只是任意文件)??

馬克

+1

您忘記在File元素的exe中設置KeyPath ='yes'。 – 2009-08-12 14:02:12

+0

謝謝,謝 - 羅布的回答似乎證實了你的說法 - 非常感謝! – 2009-08-12 20:29:23

回答

7

則ServiceInstall元素最終將指向組件的「的keyPath」則ServiceInstall是,默認情況下,WiX的工具集挑選在組件的第一個文件或的RegistryKey元素作爲的keyPath。將文件添加到組件時,列表頂部的.dll成爲KeyPath。

一般來說,較小的元件比較大的元件好。所以更好的解決方案是將您的DLL放在單獨的組件中。然後,您可以將.exe文件元素和ServiceInstall元素保留在同一個組件中。這使得它非常乾淨。

如果您希望將「服務」分組在一起,則可以創建ComponentGroup元素並將ComponentRefs放置到.exe和.dll組件。現在,您可以從Feature/ComponentGroupRef中引用一件事。

+0

+1很好的解釋 - 非常感謝,羅布!我相應地更改了我的WiX腳本,並且在每晚構建運行並且安裝已經過測試後,將會報告回來:-) – 2009-08-12 20:28:52

+0

是的,確認 - 添加「KeyPath ='yes'」解決了我的問題 - 安裝返回工作很好 - 非常感謝,Rob! – 2009-08-13 10:14:31