目录
一、下载并安装 Wix Toolset
安装完是这样子的
二、安装Visual Studio 扩展
三、准备一个待打包的项目
这里新建一个WPF项目
在Visual Studio中的项目结构如下
在硬盘内的文件结构如下,这里是生成后的Debug文件夹内文件,为了更让人易懂,这里新建一个文件夹当作项目的一些其他资源
core文件夹内容如下
四、新建一个Setup项目
这里直接新建在本示例项目解决方案一起
这里有一个是打包成exe的一个是打包msi的,本教程选择打包成 msi 格式
新建完成后Setup项目结构如下
五、添加引用待打包的项目
右键Setup项目的 References -> 添加引用 ->选择《项目》->添加待打包的项目
添加完成后的项目结构如下,这里添加好像只是添加了单个 .exe可执行文件,这里并没有过多去探索。如果不添加项目引用的话也可以在后面通过修改Product.wxs文件来添加
六、修改 Product.wxs 配置信息
配置信息可以简单理解为三部分
1、
<Product> 记录项目信息,打包清单、配置安装过程中的UI节目、环境检查等
2、
<!--片段1-->
<Fragment> 定义安装输出文件夹路径
3、
<!--片段2-->
<Fragment> 配置项目文件,依赖、图片等等
以下是配置代码,只是在我的理解范围内的解释
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!--Name="DogDemo" 控制面板里程序里的名称-->
<!--Manufacturer="Dogzi" 控制面板程序里的发布者-->
<Product Id="*" Name="DogDemo" Language="1033" Version="1.0.0.0" Manufacturer="Dogzi" UpgradeCode="11f80bba-d56d-4921-82dd-4bc58ec734f2">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<!--Feature 记录Setup打包项目的清单-->
<Feature Id="ProductFeature" Title="SetupProject2" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<!--片段1 定义安装后输出到哪些文件夹-->
<Fragment>
<!--文件夹路径一 C:\Program Files (x86)\AAAAA-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="AAAAA" />
</Directory>
</Directory>
</Fragment>
<!--片段2-->
<Fragment>
<ComponentGroup Id="ProductComponents"
Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<!--引用中的项目名称 DemoApp 对应右键References时添加的项目名称-->
<File Source="$(var.DemoApp.TargetPath)" />
<!--如果没有在Referernces中引用,则可以使用绝对路径的方式-->
<!--<File Id="DemoApp.exe" Source="F:\WPF\DemoInstall\DemoApp\bin\Debug\DemoApp.exe"/>-->
</Component>
<ComponentRef Id="Libs"/>
<ComponentRef Id="coreDir"/>
</ComponentGroup>
<!--这里可以理解为:将DirectoryRef标签下面的文件放在Id="INSTALLFOLDER"的文件夹内,INSTALLFOLDER 则是片段1中定义的安装目录-->
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="Libs">
<File Id="Newtonsoft.Json.dll"
Source="F:\WPF\DemoInstall\DemoApp\bin\Debug\Newtonsoft.Json.dll"/>
</Component>
<Directory Id="core"
Name="core">
<Component Id="coreDir">
<File Id="abc.txt"
Source="F:\WPF\DemoInstall\DemoApp\bin\Debug\core\abc.txt" />
</Component>
</Directory>
</DirectoryRef>
</Fragment>
</Wix>
连线的方式理解配置与文件对应关系
七、生成安装包并安装应用
当双击SetupProject2.msi 文件,安装过程会一闪而过,因为此配置文件中没有配置任何提示UI等。
安装后在控制面板和文件夹内的的样子
参考资料:
工具下载:WiX v3 | WiX Toolset
官方Git:wixtoolset/wix3: WiX Toolset v3.x (github.com)
博客资料:WiX Toolset 安装包制作入门教程(目录篇) - walterlv
https://blog.csdn.net/qq_35159235/article/details/118992308
https://blog.csdn.net/catshitone/article/details/77802365
https://blog.csdn.net/qq_35159235/article/details/119005674