Conversation
added 2 commits
October 1, 2026 06:12
Analyzers 与其测试项目的 Microsoft.CodeAnalysis.CSharp(.Workspaces) 由 5.9.0 降到 5.0.0, 与 global.json 所锁 SDK 10.0.1xx 自带的编译器对齐。 props/common.props 让除 Analyzers 与 Analyzers.Tests 外的全部项目以 OutputItemType=Analyzer 引用本仓分析器(PrivateAssets=all,不改任何包的依赖), 并把 CS9057 列入 WarningsAsErrors,分析器版本不兼容时构建直接失败而不是静默停用。 同步 Analyzers README 与文档站页面的编译器兼容性说明。
Utils.csproj 以普通 ProjectReference 引用 XiHan.Framework.Analyzers,打包后 XiHan.Framework.Utils 的 nuspec 带上了对 XiHan.Framework.Analyzers 的包依赖。 nuspec 中虽标了 exclude="Build,Analyzers",实测分析器仍随依赖传到所有引用框架包的 下游项目:编译器版本足够时,XHFH001 对使用者自己的每个 .cs 报警告(要求曦寒版权头); 编译器过旧时则报 CS9057。 仓库内的分析器加载已由 props/common.props 统一负责(PrivateAssets=all,不进包依赖), Utils 这条引用是多余的,删除后: - Utils 包不再依赖 Analyzers 包,框架各包均不再把分析器传给下游; - 仓库内项目仍加载分析器,XHFH001 照常检查。 想要这些规则的下游仍可显式 dotnet add package XiHan.Framework.Analyzers,行为不变。 同步 Utils、Analyzers 文档里关于两者依赖关系的描述。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
XiHan.Framework.Utils.csproj以普通ProjectReference引用XiHan.Framework.Analyzers,打包后XiHan.Framework.Utils的 nuspec 带有:虽然标了
exclude="Build,Analyzers",实测分析器仍随依赖传到所有引用框架包的下游项目(几乎所有包都间接依赖 Utils)。结果:XHFH001对使用者自己的每个.cs报警告,要求加曦寒版权头;CS9057。这条规则只应约束框架仓库本身。
用法
无需任何配置。下游引用框架包后不再出现
XHFH001。确实想用这些规则的下游仍可显式引用:改动
framework/src/XiHan.Framework.Utils/XiHan.Framework.Utils.csprojProjectReference(仓库内加载已由 #144 的props/common.props负责,PrivateAssets=all)docs/packages/utils.mddocs/packages/analyzers.md、AnalyzersREADME.md语义
XiHan.Framework.Utils不再依赖XiHan.Framework.Analyzers;仓库内除 Utils 外没有其它包引用 Analyzers,因此所有框架包都不再把分析器传给下游。XHFH001照常检查,「0 警告」门槛不变。XiHan.Framework.Analyzers包的行为不变。破坏性变更
无公开 API 变化。原先经框架包间接拿到
XHFH001/XHFA001的下游会不再看到这些诊断;需要时显式dotnet add package XiHan.Framework.Analyzers即可恢复(这就是逃生口)。测试
最小消费者项目(net10.0 类库,一个不带版权头的
.cs,PackageReference引用本机打包的XiHan.Framework.Utils 4.6.0,独立NUGET_PACKAGES与本地包源):warning XHFH001(1 个警告)warning XHFH001(1 个警告)修复后 Utils 的 nuspec 为
<group targetFramework="net10.0" />,无任何依赖。仓库内:临时删掉
Utils/Caching/CacheEvents.cs的版权头,构建报warning XHFH001指向该文件;恢复后 0 警告。验证
fork CI:通过 —— https://github.com/TW199501/XiHan.Framework/actions/runs/36803849317