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>
运行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
posted on 2022-12-02 10:32 8888888888888 阅读(266) 评论(0) 收藏 举报
浙公网安备 33010602011771号