Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

dotnet-code-analysisdotnet 代码分析

Agent Skill

dotnet-code-analysis 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

192

周安装

8

GitHub Stars

363

下载量

64
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dotnet-code-analysis(dotnet 代码分析)
来源仓库:https://github.com/managedcode/dotnet-skills
仓库路径:skills/dotnet-code-analysis
安装命令:
npx skills add https://github.com/managedcode/dotnet-skills --skill dotnet-code-analysis
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/managedcode/dotnet-skills --skill dotnet-code-analysis

简介

dotnet-code-analysis 强制执行 Roslyn 分析器的严格代码质量标准。

  • 适用于需要零警告通过的代码审查场景。
  • 提供 AnalysisLevel 和 WarningsAsErrors 的配置指导。
  • 禁止移除或降级项目的分析器严重级别设置。
  • 需结合 Directory.Build.props 统一管理规则。

SKILL.md

.NET Code Analysis

Trigger On

  • the repo wants first-party.NET analyzers
  • CI should fail on analyzer warnings
  • the team needs AnalysisLevel or AnalysisMode guidance
  • the repo needs a gradual Roslyn warning promotion strategy

Do Not Use For

  • third-party analyzer selection by itself
  • formatting-only work

Inputs

  • the nearest AGENTS.md
  • project files or Directory.Build.props
  • current analyzer severity policy

Hard Rules for AI Agents

Non-negotiable. Violating these undermines the user's explicit intent.

  1. Never disable or remove TreatWarningsAsErrors or WarningsAsErrors if the project has set them. Do not comment them out, set to false, wrap in a condition, or add <TreatWarningsAsErrors>false</TreatWarningsAsErrors> to make the build pass.
  2. Never add <NoWarn> or #pragma warning disable for warnings the user chose to treat as errors, unless the user explicitly approves the suppression.
  3. Never silently downgrade severity in .editorconfig (e.g. error to warning or none) to make a build succeed.
  4. If warnings-as-errors breaks the build — fix the code. If the fix is too large, ask the user whether to defer that warning ID.
  5. If warning volume is too large to fix in one pass — report count and categories to the user and ask which to tackle first. Do not unilaterally disable the policy.

Workflow

flowchart TD
    A[Start] --> B{New or legacy project?}
    B -->|New| C[TreatWarningsAsErrors=true immediately]
    B -->|Legacy| D[dotnet build, count warnings by ID]
    D --> E{"< 30 warnings?"}
    E -->|Yes| F[Fix all, then enable TreatWarningsAsErrors]
    E -->|No| G[Report counts to user, ask which batch first]
    G --> H[Add selected IDs to WarningsAsErrors]
    H --> I[Fix that batch, verify build]
    I --> J{More batches?}
    J -->|Yes| G
    J -->|No| F
    C --> K[Set AnalysisLevel latest-recommended]
    F --> K
    K --> L[Promote security CA3xxx/CA5xxx to error in .editorconfig]
    L --> M[Validate: build + CI green]
  1. Start with SDK analyzers before third-party packages.
  2. Detect project maturity: new or existing/legacy.
  3. Enable EnableNETAnalyzers, AnalysisLevel, AnalysisMode in Directory.Build.props.
  4. Apply the right warning promotion strategy (see below).
  5. Per-rule severity goes in repo-root .editorconfig.
  6. dotnet build is the analyzer gate in CI.

Warning Promotion Strategy

New Projects

Set these in Directory.Build.props immediately:

  • TreatWarningsAsErrors = true
  • AnalysisLevel = latest-recommended
  • Security category = error in .editorconfig

Fix all warnings before merging.

Legacy Projects — Gradual Promotion

Blanket TreatWarningsAsErrors on a legacy codebase produces hundreds/thousands of errors. An agent cannot fix them all at once — context floods, fix quality drops. Promote in batches.

Phase 1: Trivial Hygiene (start here)

Mechanical fixes, lowest effort:

  • CS8019 — unnecessary using directive (remove it)
  • CS0219 — variable assigned but never used (remove it)
  • CS0168 — variable declared but never used (remove it)
  • CS1591 — missing XML comment for public member (add comment or disable for internal code)
  • CS0612 — obsolete member used, no message (replace with non-obsolete API)
  • CS0618 — obsolete member used, with message (follow migration guidance)

Add to WarningsAsErrors: CS8019;CS0219;CS0168. Fix all, then Phase 2.

Phase 2: Code Quality (ask user which categories)

  • CA2000 — dispose objects before losing scope (Reliability)
  • CA1062 — validate public method arguments (Design)
  • CA1822 — mark members as static (Performance)
  • CA1860 — avoid Enumerable.Any() for length check (Performance)
  • CA1861 — avoid constant arrays as arguments (Performance)
  • CA2007 — consider calling ConfigureAwait (Reliability)
  • CS8600–CS8610 — nullable reference type warnings (Nullability)

Ask: "Which categories next — Nullability, Performance, or Reliability?" Add selected IDs to WarningsAsErrors, fix, repeat.

Phase 3: Security (always promote early)

Set in .editorconfig regardless of project maturity:

[*.cs]
dotnet_analyzer_diagnostic.category-Security.severity = error

Covers CA3001 (SQL injection), CA3002 (XSS), CA3003 (path injection), CA3075 (insecure DTD), CA5350/CA5351 (weak crypto), CA5394 (insecure randomness).

Phase 4: Full Coverage

Once all batches pass, transition to:

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CA1707</WarningsNotAsErrors> <!-- explicit exceptions only -->

Interaction Protocol (legacy codebases)

  1. Run dotnet build, count warnings by ID.
  2. Report summary: "Found 47 CS8019, 23 CA1822, 12 CA2000, 8 CS8600."
  3. Ask which batch to tackle. Recommend starting with Phase 1.
  4. Fix selected batch, verify build.
  5. Add those IDs to WarningsAsErrors.
  6. Report back, ask about next batch.

Never skip the ask step. The user decides the pace.

Bootstrap When Missing

  1. Detect current state:

- dotnet --info - rg -n "EnableNETAnalyzers|AnalysisLevel|AnalysisMode|TreatWarningsAsErrors|WarningsAsErrors" -g '*.csproj' -g 'Directory.Build.*'. - dotnet build SOLUTION_OR_PROJECT 2>&1 — count warnings by ID

  1. Classify: new (few/zero warnings) vs legacy (many warnings).
  2. Enable EnableNETAnalyzers, AnalysisLevel, AnalysisMode in MSBuild config.
  3. Apply promotion strategy matching project maturity.
  4. Per-rule severity in repo-root .editorconfig.
  5. Run dotnet build, return status: configured or status: improved.
  6. If repo defers analyzer policy to another build layer, return status: not_applicable.

Deliver

  • explicit, reviewable first-party analyzer policy
  • build-time analyzer execution for CI
  • warning promotion plan matching project maturity

Validate

  • analyzer behavior driven by repo config, not IDE defaults
  • CI reproduces same warnings/errors locally
  • no TreatWarningsAsErrors, WarningsAsErrors, or severity settings removed/weakened without user approval
  • promoted warnings produce build errors, not just IDE hints

Ralph Loop

  1. Plan: analyze state, define target, constraints, risks, execution plan, validation steps.
  2. Execute one step, produce concrete delta.
  3. Review result, capture findings.
  4. Apply fixes in small batches, rerun checks.
  5. Update plan after each iteration.
  6. Repeat until acceptable or only explicit exceptions remain.
  7. Missing dependency: bootstrap or return status: not_applicable.

Required Result Format

  • status: complete | clean | improved | configured | not_applicable | blocked
  • plan: concise plan and current step
  • actions_taken: concrete changes
  • validation_skills: final skills run or skipped with reasons
  • verification: commands, checks, or review evidence
  • remaining: unresolved items or none

Load References

  • references/rules.md
  • references/config.md
  • references/code-analysis.md

Example Requests

  • "Turn on built-in.NET analyzers."
  • "Make analyzer warnings fail the build."
  • "Set the right AnalysisLevel for this repo."
  • "Start treating unused usings and unused variables as errors."
  • "Help me gradually promote Roslyn warnings in my legacy project."
  • "Which warnings should I promote to errors next?"

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.86%
按下载量换算22

Claude

31.87%
按下载量换算20

Cursor

19.17%
按下载量换算12

Gemini CLI

9.18%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills