1. 程式人生 > 其它 >Wix打包軟體使用(樣例)

Wix打包軟體使用(樣例)

需求:
專案編譯好的Windows exe程式、dll以及其他的資原始檔,在一個專案資料夾中,需要打包成一個安裝程式;
包含多個檔案和巢狀的資料夾;
用包含logo的圖片,替換安裝程式窗體的預設背景;
安裝後,生成桌面快捷方式;
工具:
WIX Toolset - https://wixtoolset.org/

實現過程:
利用工具中的heat.exe將整個資料夾匯出為temp.wxs檔案,注意選擇componentgroup -cg選項
heat.exe dir "Your_Project_Path" -cg Package -gg -sfrag -template fragment -out temp.wxs

將temp.wxs檔案中,<fragment>內的內容全部複製到Example_Installer.wxs檔案中
注意修改從temp.exe中複製內容的部分欄位
根據實際情況修改Example_Installer.wxs檔案,最終如下

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="7F503FBC-5FD5-4AFB-9E02-87088B2A5027" Name="Your_Product_Name" Language
="1033" Version="1.0.0" Manufacturer="Developer_Name" UpgradeCode="81519c22-b44c-48c0-bf19-f045500d8a37"> <Package Id='*' Keywords='Installer' Description="Description of this Installer" Comments='Something you want to comment' Manufacturer='Developer_Name' InstallerVersion='100' Languages='1033' Compressed
='yes' /> <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> <!-- 打包過程中,不生成額外的cab檔案,只會生成一個單獨的安裝程式檔案 --> <Media Id="1" Cabinet="Cab1.cab" EmbedCab="yes" /> <!-- Feature中的Component就是會被打包的內容,Id為後面定義的component元件的Id --> <Feature Id='Complete' Title='Installer_Name' Level='1'> <ComponentRef Id='MainExecutable' /> <ComponentRef Id='ProgramMenuDir' /> <ComponentGroupRef Id="Package" /> </Feature> <!-- 設定安裝過程中的預設路徑(Value) --> <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" /> <!-- 選擇安裝過程的UI樣式,參考官方文件 --> <UIRef Id="WixUI_InstallDir" /> <UIRef Id="WixUI_ErrorProgressText" /> <!-- 自定義安裝過程中顯示的內容,License檔案、banner圖片、Dialog圖片,圖片格式可參考官方文件 --> <WixVariable Id="WixUILicenseRtf" Value="Your_Project_Path\License.rtf" /> <WixVariable Id="WixUIBannerBmp" Value="Your_Project_Path\banner.bmp" /> <WixVariable Id="WixUIDialogBmp" Value="Your_Project_Path\dialog.bmp" /> <!-- 定義Icon --> <Icon Id="app.exe" SourceFile="Your_Project_Path\app.exe" /> </Product> <Fragment> <!-- 定義預設安裝路徑, "TARGETDIR"、"ProgramFilesFolder",為Wix關鍵字 --> <!-- "INSTALLDIR",自定義ID, "Installation_Folder_Name", 安裝目錄的名稱 --> <!-- 此設定下,預設路徑為:"C:\Program Files (x86)\Installation_Folder_Name" --> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="INSTALLDIR" Name="Installation_Folder_Name"> <!-- 定義Component,Id可自定義,Guid 可用相關工具生成,為確保相容性,所有字母大寫, --> <Component Id="MainExecutable" Guid="4D6724F4-FCCD-45BE-AE76-A17E6EF52674"> <!-- 定義Component中包含的檔案,一個Component中可包含多個檔案 --> <File Id="DWLCEXE" Name="app.exe" Source="Your_Project_Path\app.exe" KeyPath="yes"> <!-- 定義快捷方式 --> <Shortcut Id="startmenuDWLC10" Directory="ProgramMenuDir" Name="DWLC Greatec M3" WorkingDirectory='INSTALLDIR' Icon="app.exe" IconIndex="0" Advertise="yes" /> <Shortcut Id="desktopDWLC10" Directory="DesktopFolder" Name="DWLC Greatec M3" WorkingDirectory='INSTALLDIR' Icon="app.exe" IconIndex="0" Advertise="yes" /> </File> </Component> </Directory> </Directory> <!-- 解除安裝後,刪除相應的快捷方式,具體可參考官方文件 --> <Directory Id="ProgramMenuFolder" Name="Programs"> <Directory Id="ProgramMenuDir" Name="DWLC Greatec M3"> <Component Id="ProgramMenuDir" Guid="215DBA0A-1037-4011-8294-505F05B04204"> <RemoveFolder Id='ProgramMenuDir' On='uninstall' /> <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' /> </Component> </Directory> </Directory> <Directory Id="DesktopFolder" Name="Desktop" /> </Directory> </Fragment> <!-- 從temp.wxs中複製的內容,利用heat.exe生成,包含專案資料夾的所有內容 --> <Fragment> <!-- Id 必須與前面保持一直 --> <DirectoryRef Id="INSTALLDIR"> <Component Id="cmp6FB3FEE7CE6997D320BE35F806D58FAF" Guid="{45AB4823-ED77-4840-B680-45DA35B950E1}"> <File Id="fil89BB5CA2C9B2A7F57FD2F15883D3763E" KeyPath="yes" Source="Your_Project_Path\xx1.dll" /> </Component> <!-- 因為之前單獨定義過app.exe,所以此處將其註釋掉 --> <!-- <Component Id="cmp30CC91312ED0AD2C2D4EED633AA299C3" Guid="{0CA468B5-2716-4208-93C7-D64BC20F04EE}"> <File Id="fil09B510D7AD2022C92336AAFF4207563E" KeyPath="yes" Source="Your_Project_Path\app.exe" /> </Component> --> <Component Id="cmpC32E26C3450E497DC6B040064E22F874" Guid="{519D1BA4-BFC8-4B89-9180-C5FA88D12430}"> <File Id="fil2BE574489D23056A361B35B7316F381D" KeyPath="yes" Source="Your_Project_Path\xx2.dll" /> </Component> <Component Id="cmpDCAF26179A917EDF4A24FCD84E4DD931" Guid="{4736E7A8-1180-44CD-A2D0-B91225372BD5}"> <File Id="filE8A91A263295B0B8CA6B1CA52839CB70" KeyPath="yes" Source="Your_Project_Path\xx3.dll" /> </Component> <!-- 此處省略一萬字。。。 --> </DirectoryRef> </Fragment> <!-- 從temp.wxs中複製的內容,利用heat.exe生成,引用Component Id成一個ComponentGroup,以便在Feature中新增。 --> <Fragment> <ComponentGroup Id="Package"> <ComponentRef Id="cmp6FB3FEE7CE6997D320BE35F806D58FAF" /> <!-- 因為之前單獨定義過app.exe,所以此處將其註釋掉 --> <!-- <ComponentRef Id="cmp30CC91312ED0AD2C2D4EED633AA299C3" /> --> <ComponentRef Id="cmpC32E26C3450E497DC6B040064E22F874" /> <ComponentRef Id="cmpDCAF26179A917EDF4A24FCD84E4DD931" /> <!-- 此處省略一萬字。。。 --> </ComponentGroup> </Fragment> </Wix>
View Code


執行candle.exe,生成wix物件檔案
candle.exe Example_Installer.wxs
執行light.exe,生成安裝程式,
light.exe -ext WixUIExtension Example_Installer.wixobj
最終得到,Example_Installer.exe
————————————————
版權宣告:本文為CSDN博主「Tnix」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/zerg_nick/article/details/102636516