Bloxstrap安装包制作:使用WiX Toolset创建安装程序
你是否还在为Bloxstrap的手动部署烦恼?本文将带你使用WiX Toolset(Windows Installer XML工具集)快速创建专业的Windows安装程序,无需复杂的手动配置,让用户一键完成安装。读完本文,你将掌握从环境准备到安装包发布的完整流程,包含WiX项目配置、安装逻辑编写和自动化构建技巧。
准备工作:环境与工具
开始前需要准备以下工具和环境:
- .NET 6 Desktop Runtime(Bloxstrap运行依赖)
- WiX Toolset 3.11+(安装包制作工具)
- Visual Studio 2022(可选,提供WiX项目模板支持)
Bloxstrap的发布配置已预设在项目中,可通过Bloxstrap/Properties/PublishProfiles/Publish-x64.pubxml查看详细发布参数,其中定义了输出目录、运行时标识等关键配置:
<PublishDir>bin\Release\net6.0-windows\publish\win-x64\</PublishDir>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
项目结构:WiX安装包工程
在Bloxstrap解决方案中添加WiX项目,推荐结构如下:
Bloxstrap.Installer/
├─ Product.wxs // 主安装配置
├─ Components.wxs // 组件定义
├─ Directories.wxs // 目录结构
└─ Icons/ // 安装程序图标
WiX通过XML格式的.wxs文件定义安装逻辑,核心文件功能如下:
- Product.wxs:定义产品元数据(版本、制造商、升级策略)
- Components.wxs:声明待安装文件、注册表项等资源
- Directories.wxs:指定文件安装路径和目录权限
核心配置:编写WiX安装脚本
产品元数据配置
在Product.wxs中定义产品基本信息,需与Bloxstrap版本保持一致:
<Product Id="*" Name="Bloxstrap" Language="1033" Version="2.9.0"
Manufacturer="Bloxstrap Labs" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perUser" />
<MajorUpgrade DowngradeErrorMessage="较新版本已安装" />
<MediaTemplate EmbedCab="yes" />
<!-- 引用其他配置文件 -->
<Feature Id="ProductFeature" Title="Bloxstrap" Level="1">
<ComponentGroupRef Id="ApplicationComponents" />
</Feature>
</Product>
安装目录定义
在Directories.wxs中配置安装路径,默认遵循Bloxstrap的安装位置规范:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="LocalAppDataFolder">
<Directory Id="INSTALLFOLDER" Name="Bloxstrap" />
</Directory>
<Directory Id="DesktopFolder" Name="Desktop" />
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuDir" Name="Bloxstrap" />
</Directory>
</Directory>
组件与文件关联
在Components.wxs中声明应用程序文件组件,需包含发布输出的所有文件:
<ComponentGroup Id="ApplicationComponents" Directory="INSTALLFOLDER">
<!-- 主程序文件 -->
<Component Id="Bloxstrap.exe">
<File Source="$(var.Bloxstrap.TargetDir)Bloxstrap.exe" KeyPath="yes" />
</Component>
<!-- 依赖文件 -->
<Component Id="Bloxstrap.dll">
<File Source="$(var.Bloxstrap.TargetDir)Bloxstrap.dll" />
</Component>
<!-- 快捷方式 -->
<Component Id="DesktopShortcut" Guid="*">
<Shortcut Id="DesktopShortcut" Name="Bloxstrap"
Target="[INSTALLFOLDER]Bloxstrap.exe" WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder On="uninstall" Id="DesktopFolder" />
<RegistryValue Root="HKCU" Key="Software\Bloxstrap" Name="installed"
Type="integer" Value="1" KeyPath="yes" />
</Component>
</ComponentGroup>
功能实现:高级安装逻辑
注册表配置
Bloxstrap需要注册URL协议和文件关联,通过WiX的RegistryValue元素实现:
<Component Id="RegistryEntries">
<RegistryKey Root="HKCU" Key="Software\Classes\roblox-player\shell\open\command">
<RegistryValue Type="string" Value=""[INSTALLFOLDER]Bloxstrap.exe" %1" />
</RegistryKey>
</Component>
这对应Bloxstrap源码中Bloxstrap/Installer.cs的注册表操作逻辑:
WindowsRegistry.RegisterPlayer(); // 注册Roblox协议处理
安装前检查
添加自定义操作验证.NET运行时环境,确保满足README.md中提到的依赖要求:
<CustomAction Id="CheckDotNet" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="immediate" Return="check">
<![CDATA["dotnet" --list-runtimes | findstr /i "Microsoft.WindowsDesktop.App 6.0"]]>
</CustomAction>
<InstallExecuteSequence>
<Custom Action="CheckDotNet" Before="CostInitialize" />
</InstallExecuteSequence>
构建与测试:生成MSI安装包
命令行构建
使用WiX的candle和light工具编译安装包:
candle -dBloxstrap.TargetDir=../Bloxstrap/bin/Release/net6.0-windows/publish/win-x64/ *.wxs
light -out BloxstrapSetup.msi Product.wixobj Components.wixobj Directories.wixobj
自动化构建集成
将WiX构建步骤添加到GitHub Actions工作流,修改.github/workflows/ci.yml:
- name: Build MSI with WiX
run: |
candle -dBloxstrap.TargetDir=Bloxstrap/bin/Release/net6.0-windows/publish/win-x64/ Bloxstrap.Installer/*.wxs
light -out BloxstrapSetup.msi Bloxstrap.Installer/*.wixobj
测试验证:安装流程验证
安装包构建完成后,需验证以下关键流程:
- 安装路径:默认应安装到
%LOCALAPPDATA%\Bloxstrap - 快捷方式:桌面和开始菜单是否正确创建
- 协议关联:浏览器打开Roblox链接是否启动Bloxstrap
- 卸载功能:通过控制面板卸载是否完全清理残留
可参考Bloxstrap官方安装指南中的验证步骤,确保与手动安装行为一致。
总结与扩展
本文介绍了使用WiX Toolset为Bloxstrap创建安装包的完整流程,涵盖项目配置、脚本编写和自动化构建。通过WiX的强大功能,可以实现专业的安装体验,包括版本升级、注册表配置和快捷方式管理。
进阶优化方向:
- 添加安装界面自定义(使用WiX Burn创建引导程序)
- 实现安装包数字签名(确保Windows SmartScreen信任)
- 集成自动更新检查(关联Bloxstrap的版本检测逻辑)
完整安装包制作示例可参考Bloxstrap官方仓库的发布工作流,其中包含从代码编译到安装包生成的全自动化流程。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



