packServer/desktop/YuncangTrace.LocalService.csproj
liufumingren fb896272f4 桌面端接入 .NET 8 SDK 并首编译通过;服务地址改为构建期环境配置(开发/生产)
一、工具链
- 本机没有 .NET,微软域名又被网络阻断,改用 curl 从 builds.dotnet.microsoft.com 拉
  dotnet-sdk-8.0.426-win-x64.zip,解压到 %LOCALAPPDATA%\Microsoft\dotnet(免管理员),
  并写入用户 PATH / DOTNET_ROOT / DOTNET_CLI_TELEMETRY_OPTOUT。

二、首次编译暴露的两个真实缺陷(都已修复)
- ProtocolHelper.cs 缺 using System.Collections.Generic(ImplicitUsings=disable 后
  IEnumerable<string> 找不到)。
- App.xaml 少了 BgBrush,LoginWindow/MainWindow 用 StaticResource 引用它 → 编译期查不出,
  运行期一弹登录窗就 XamlParseException 直接退出(事件日志里能看到)。
  已补 BgBrush=#F5F7FA 并注明「缺一个就会运行时炸」。
- 顺带把 WFAC010(WinForms 建议 DPI 改走 ApplicationHighDpiMode)压掉并写明原因:
  本程序宿主是 WPF,走不到 WinForms 的 ApplicationConfiguration,DPI 只能由 manifest 决定。

三、服务地址 = 构建期环境(对齐前端 VITE_BACKEND 的思路)
- csproj:Debug → AppEnvironment=Development、ServerBaseUrl=http://127.0.0.1:7300;
  Release → Production、占位 https://packs.example.com;用 -p:ServerBaseUrl= 覆盖;
  两者通过 AssemblyMetadataAttribute 写进程序集,exe 自带「我是哪个环境」。
- 新增 Services/BuildInfo.cs 读元数据(带兜底,绝不抛)。
- AppSettings:默认值改为 BuildInfo.DefaultServer;等于内置默认值时不落盘(换构建能自动跟随),
  老版本已把默认值写进 settings.json 的也识别为"没改过";新增 UseServer() 支持运行时临时覆盖。
- App:解析 --server=xxx / -s xxx,其次 YUNCANG_SERVER 环境变量,写在构建默认值之前。
- 登录窗:「服务器地址」改叫「服务地址」,右侧显示"开发环境/生产环境"(只展示,由构建决定),
  输入框 ToolTip 说明留空即用当前环境默认地址。
- /api/health 增加 env(Development/Production)与 server(当前后端地址),排障一眼看出装错没有。

四、验证
- Debug / Release / Release+域名覆盖 三种构建均 0 警告 0 错误;
- Debug:health 返回 env=Development、server=http://127.0.0.1:7300;
- Release:env=Production、server=https://packs.example.com;
  Release 加 -p:ServerBaseUrl=https://trace.yuncang.cn 后 server 随之变化;
- 带 --server=http://10.0.0.9:7300 启动:server 被覆盖,settings.json 未被污染;
- health / 未登录 query(401) / activate-login(200,登录窗弹出) / OPTIONS 预检(204+CORS) 全部正常。
- 注意:改 -p: 属性必须 -t:Rebuild,否则 MSBuild 不会重新生成 AssemblyInfo。

五、README
- 新增「环境配置(开发 / 生产)」:构建矩阵、发布时覆盖域名、优先级、默认值不落盘的原因、
  settings.json/session.json 的行为;补了本机 SDK 装在用户目录、需要 DOTNET_ROOT 的说明;
  行为表新增「网页请求唤起登录」一行;health 返回字段更新。
2026-10-17 10:48:11 +08:00

65 lines
3.1 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.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<!-- WPF 只能跑在 Windows 上;net8.0-windows 是当前 LTS -->
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<!-- 托盘图标用 WinForms 的 NotifyIcon(WPF 没有内置托盘) -->
<UseWindowsForms>true</UseWindowsForms>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<!--
⚠️ 必须关掉隐式 using:WPF 与 WinForms 同时开启时,两边的隐式命名空间会让
MessageBox / Application / Clipboard / Point 等类型产生歧义(编译不过)。
各文件里显式 using 自己需要的命名空间。
-->
<ImplicitUsings>disable</ImplicitUsings>
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
<!-- 产物名/程序集名(安装包里 exe 就叫这个) -->
<AssemblyName>YuncangTrace.LocalService</AssemblyName>
<RootNamespace>YuncangTrace.LocalService</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<!--
WFAC010:WinForms 分析器建议把高 DPI 从 manifest 挪到 ApplicationHighDpiMode。
但本程序是 WPF 宿主(走的是 WPF 的 App.Run,不会调 WinForms 的 ApplicationConfiguration),
WinForms 只用来放托盘图标 —— 那条建议在这里不生效,DPI 只能由 manifest 的 PerMonitorV2 决定。
-->
<NoWarn>$(NoWarn);WFAC010</NoWarn>
<!--
环境配置(和前端 VITE_BACKEND 一个思路:由构建决定,不靠用户手填)
Debug :AppEnvironment=Development,默认后端 http://127.0.0.1:7300(= 前端 dev 代理的地址)
Release :AppEnvironment=Production ,默认后端由 -p:ServerBaseUrl=https://正式域名 覆盖
运行时覆盖优先级:命令行 server 参数 &gt; YUNCANG_SERVER 环境变量 &gt; 这里注入的默认值。
-->
<AppEnvironment Condition="'$(Configuration)' == 'Debug'">Development</AppEnvironment>
<AppEnvironment Condition="'$(Configuration)' == 'Release'">Production</AppEnvironment>
<ServerBaseUrl Condition="'$(Configuration)' == 'Debug' and '$(ServerBaseUrl)' == ''">http://127.0.0.1:7300</ServerBaseUrl>
<ServerBaseUrl Condition="'$(Configuration)' == 'Release' and '$(ServerBaseUrl)' == ''">https://packs.example.com</ServerBaseUrl>
<Version>1.0.0</Version>
<Product>云仓视频溯源软件</Product>
<Company>云仓</Company>
<AssemblyTitle>云仓视频溯源软件(本机服务)</AssemblyTitle>
<NeutralLanguage>zh-CN</NeutralLanguage>
</PropertyGroup>
<!-- 把环境写进程序集(Services/BuildInfo.cs 运行时读出来) -->
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>AppEnvironment</_Parameter1>
<_Parameter2>$(AppEnvironment)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ServerBaseUrl</_Parameter1>
<_Parameter2>$(ServerBaseUrl)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Project>