liufumingren 77b5713d02 新增 MSI 安装包:安装即注册 yuncang:// 协议,卸载自动取消注册
需求:打包安装包;协议在**安装时**注册(不依赖先启动软件一次);卸载能清掉注册。

实现(desktop/installer/):
- Product.wxs(WiX 5):
  - Scope=perUser(免管理员、无 UAC),安装到 %LOCALAPPDATA%\Programs\YuncangTrace;
  - Component 里写 HKCU\Software\Classes\yuncang(默认值 / URL Protocol / shell\open\command),
    注册表项属于 MSI 组件 → **卸载时自动删除**,即「取消注册」;
  - 开始菜单快捷方式(RemoveFolder On=uninstall);
  - MajorUpgrade(升级替换、拒绝降级);用户数据 settings/session.json 不在安装目录,卸载保留。
  - 版本号用 $(var.Version) 由构建命令注入,避免和 csproj 两处维护。
- build.ps1:读取 csproj 的 <Version> → dotnet publish(自包含单文件)→ wix build
  → out\YuncangTraceSetup-<版本>.msi。
  ⚠️ 脚本保存为 UTF-8 with BOM:PowerShell 5.1 读无 BOM 脚本会按 GBK 解析,中文注释会让语法报错。
- 工具链:`dotnet tool install --global wix --version 5.0.2`
  (WiX v7 会要求接受 OSMF 付费维护费协议,改用 v5)。

实测(perUser 静默安装 → 协议 → 唤起 → 卸载):
- 安装:文件落到 %LOCALAPPDATA%\Programs\YuncangTrace,HKCU 协议立即指向安装目录
  (安装前指向 desktop\publish,安装后被正确覆盖),开始菜单快捷方式已创建;
- **不启动软件**,直接 Start-Process "yuncang://open?code=INSTALLTEST":
  进程路径 = 安装目录 exe,日志显示 "已恢复登录:管理员 → 收到启动协议 → 查询:INSTALLTEST";
- 卸载:安装目录删除、HKCU 协议删除、开始菜单删除,均无残留;
- build.ps1 完整跑通,产物 54.1 MB(cab 压缩)。

.gitignore:忽略 desktop/installer/out/ 与 *.wixpdb。
desktop/README.md:新增「打安装包(MSI)」章节(构建命令、安装范围、协议注册/卸载行为、
perMachine 改法、BOM 提醒)。
2026-10-17 11:49:26 +08:00

87 lines
3.7 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!--
云仓视频溯源软件(本机服务)—— MSI 安装包定义
设计要点:
- **perUser 安装**(免管理员、无 UAC):装到 %LOCALAPPDATA%\Programs\YuncangTrace;
- **安装即注册启动协议** yuncang://(HKCU\Software\Classes),不用先启动软件;
- 注册表项属于安装包的组件 → **卸载时 MSI 自动删除(= 取消注册)**;
- 升级:MajorUpgrade;同版本重装走「修复/重装」。
构建(wix 是 dotnet 全局工具,推荐 build.ps1 一键完成):
wix build Product.wxs -arch x64 -d Version=1.0.0 -o out\YuncangTraceSetup-1.0.0.msi
发布产物要先有:desktop\publish\YuncangTrace.LocalService.exe
-->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="云仓视频溯源软件"
Manufacturer="云仓"
Version="$(var.Version)"
UpgradeCode="A1E7CF0F-4FC5-4A88-84B5-13E818F352CC"
Scope="perUser"
Compressed="yes">
<!-- 高版本已装时不允许降级安装 -->
<MajorUpgrade DowngradeErrorMessage="已安装更新版本的云仓视频溯源软件,请先在「应用和功能」里卸载旧版本。" />
<MediaTemplate EmbedCab="yes" />
<!-- 安装目录:%LOCALAPPDATA%\Programs\YuncangTrace -->
<StandardDirectory Id="LocalAppDataFolder">
<Directory Id="ProgramsFolder" Name="Programs">
<Directory Id="INSTALLFOLDER" Name="YuncangTrace" />
</Directory>
</StandardDirectory>
<!-- 开始菜单 -->
<StandardDirectory Id="ProgramMenuFolder">
<Directory Id="AppMenuFolder" Name="云仓视频溯源软件" />
</StandardDirectory>
<Feature Id="Main" Title="云仓视频溯源软件" Level="1">
<ComponentGroupRef Id="AppComponents" />
</Feature>
</Package>
<Fragment>
<ComponentGroup Id="AppComponents" Directory="INSTALLFOLDER">
<!-- 主程序(单文件自包含 exe) -->
<Component Id="MainExe" Guid="C779B513-9C6B-4BEC-A963-3AF1E53FEC30">
<File Id="MainExeFile"
Source="..\publish\YuncangTrace.LocalService.exe"
KeyPath="yes" />
</Component>
<!--
启动协议 yuncang://open?code=xxx
写 HKCU(perUser 安装):安装完成即可被浏览器唤起;
卸载时随组件一起删除,不会留下无效协议。
-->
<Component Id="Protocol" Guid="857877CC-C14C-4F17-A0C6-49D5852E0D2E">
<RegistryKey Root="HKCU" Key="Software\Classes\yuncang">
<RegistryValue Type="string" Value="URL:云仓视频溯源软件" KeyPath="yes" />
<RegistryValue Name="URL Protocol" Type="string" Value="" />
<RegistryKey Key="shell\open\command">
<RegistryValue Type="string"
Value="&quot;[INSTALLFOLDER]YuncangTrace.LocalService.exe&quot; &quot;%1&quot;" />
</RegistryKey>
</RegistryKey>
</Component>
<!-- 开始菜单快捷方式(卸载时连文件夹一起删) -->
<Component Id="StartMenuShortcut" Directory="AppMenuFolder" Guid="6CE6EE8C-98FD-475F-947B-E365EBA41569">
<Shortcut Id="AppShortcut"
Name="云仓视频溯源软件"
Description="本机打印与溯源服务(打开后最小化到托盘)"
Target="[INSTALLFOLDER]YuncangTrace.LocalService.exe"
WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveAppMenuFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\YuncangTrace\Install"
Name="StartMenuShortcut" Type="integer" Value="1" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>