packServer/desktop/nuget.config
liufumingren 30ad162c69 修复唤起:协议自动指向当前 exe + 单实例监听提前 + 自包含发布(不再依赖 DOTNET_ROOT)
现象:网页点「启动本机软件」/双击 exe 弹「You must install .NET Desktop Runtime」,
网页表现为唤起没反应、查询失败。

根因有两个:
1. 协议注册表指向的是 bin\Debug 的 framework-dependent exe,它靠 DOTNET_ROOT 找运行时;
   而浏览器/资源管理器/协议拉起的进程拿不到我们临时设的环境变量 → 直接弹安装提示。
   更糟的是协议只在主窗口手动点按钮才注册,换目录/换构建后注册表一直是旧路径。
2. 单实例的命名管道监听是在「登录完成、主窗口出现」之后才 StartListening,
   用户卡在登录窗期间被协议唤起 → 参数无人接收(第二个实例连不上管道就直接退出了)。

修复:
- App.EnsureProtocolRegistered():每次启动把 HKCU 的 command 校正到 Environment.ProcessPath,
  与当前 exe 一致时跳过(幂等);不一致时重注册并记日志(含原路径,方便排查)。
- _single.StartListening() 提前到启动服务之后、登录之前。
- 登录期间收到唤起:存 pending code 并把登录窗叫到前面,登录完成后自动查询(原有逻辑保留)。
- 抽出 BringLoginWindowToFront(),OnLoginRequested / 第二次双击(不带 URL)也走它——
  以前登录期间再双击 exe 是彻底没反应的。
- MainWindow 的协议状态改为显示「是否指向当前 exe」,指向旧路径时提示重启会自动校正。

分发形态改为自包含:
- desktop/nuget.config 指向华为云 NuGet 镜像(本机访问不了 api.nuget.org),
  自包含发布要下载 Microsoft.*.App.Runtime.win-x64;
- dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true
  -p:IncludeNativeLibrariesForSelfExtract=true -o publish → 单文件约 154 MB,双击/协议唤起都能直接跑。
- publish/ 已在 .gitignore 里。

实测(全程清掉 DOTNET_ROOT,模拟用户环境):
- 冷启动:yuncang://open?code=COLD123 → 进程起来 → 恢复登录 → 自动查询 COLD123;
- 已运行时:yuncang://open?code=TEST999 → 管道转发到原实例 → 主窗口前置并查询;
- 注册表自动从 bin\Debug 校正到 publish\...exe(日志有记录);
- 网页 /local?code=ABC123 → 已登录 → 正常展示查询结果(真实桌面端,非 mock)。
2026-10-17 10:58:03 +08:00

13 lines
575 B
XML
Raw Permalink 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"?>
<!--
国内网络访问不了 api.nuget.org(TLS 握手失败),这里指向华为云 NuGet 镜像。
⚠️ 只在 desktop/ 目录生效(自包含发布要下载 Microsoft.*.App.Runtime.win-x64 运行时包)。
换了网络环境(能直连 nuget.org)也不会出问题:镜像只是代理,包内容一致。
-->
<configuration>
<packageSources>
<clear />
<add key="huawei" value="https://mirrors.huaweicloud.com/repository/nuget/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>