AgentLint 实测验证 95/100基于 99 个 C# / .NET 开源仓库统计
C# / .NET CLAUDE.md & AGENTS.md 模板
dotnet test --filter 精准过滤、可空引用类型保护与分析器严格门禁,提炼自 99 个 C# 仓库。
# C# / .NET Project — C# / .NET Harness .NET 9 solution with nullable reference types enabled, xUnit tests, and analyzer warnings treated as errors. ## Commands - Fast targeted test: `dotnet test --no-restore --filter FullyQualifiedName~BillingTests` - Full suite: `dotnet test` - Format check: `dotnet format --verify-no-changes` - Strict build: `dotnet build --warnaserror` ## Rules - Don't silence nullable warnings with the null-forgiving operator `!`. Instead validate inputs and return typed results. Because `!` turns compile-time safety into runtime exceptions. - Don't block on async calls with `.Result` or `.Wait()`. Instead propagate `async`/`await` with `CancellationToken`. Because sync-over-async causes thread-pool starvation. - When editing EF Core models, read `docs/ef-migrations.md` first. ## Continuity - Keep `appsettings.Development.json` secrets in User Secrets, never in git, and update `HANDOFF.md`.
C# / .NET 开源生态中最常采用的工程规则
基于 4,533 仓库研究中 99 个公开 C# / .NET 仓库的实测统计:
dotnet-cli工具链
Use dotnet CLI
65.7%65 个仓库
unit-tests测试
Write unit tests for all changes
47.5%47 个仓库
xunit测试
xUnit for testing
38.4%38 个仓库
async-await-csharp代码规范
async/await patterns
35.4%35 个仓库
entity-framework工具链
Entity Framework for ORM
30.3%30 个仓库
error-handling代码规范
Proper error handling with context
28.3%28 个仓库
docker工具链
Docker for containerization
28.3%28 个仓库
conventional-commits工作流
Use conventional commit messages
22.2%22 个仓库
必写验证命令(对应规则 W1 与 W7)
- 安装依赖
- dotnet restore
- 快速单测(秒级迭代)
- dotnet test --no-restore --filter FullyQualifiedName~TargetTests
- 全量测试
- dotnet test
- Lint 与静态检查
- dotnet format --verify-no-changes
- 生产构建
- dotnet build --warnaserror
C# / .NET 项目中 AI 代理常见踩坑
- 01不加
--filter会重编并执行整个解决方案下的所有测试项目。 - 02AI 用
!(null-forgiving 运算符)屏蔽编译告警,把编译期错误变成线上空引用异常。