dotnet-init

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/dotnet-init

/dotnet-init

What

功能概述

Interactively initializes a .NET project for use with dotnet-claude-kit. Detects the project type, asks targeted questions about architecture and tech stack, then generates a fully customized
CLAUDE.md
in the project root.
No manual template copying required.
交互式初始化可适配dotnet-claude-kit的.NET项目。检测项目类型,针对架构和技术栈提出定向问题,随后在项目根目录生成完全自定义的
CLAUDE.md
文件。
无需手动复制模板。

When

适用场景

  • Starting a new .NET project with Claude Code
  • Adding dotnet-claude-kit to an existing project
  • "init project", "setup project", "generate CLAUDE.md", "configure for dotnet-claude-kit"
  • 使用Claude Code启动新的.NET项目时
  • 为现有项目添加dotnet-claude-kit时
  • 执行「init project」「setup project」「generate CLAUDE.md」「configure for dotnet-claude-kit」命令时

How

操作步骤

Step 1: Detect or Ask Project Type

步骤1:检测或询问项目类型

Analyze the current directory to determine if this is an existing or greenfield project:
→ Look for .slnx / .sln files
→ If found, scan .csproj files for SDK type:
  - Microsoft.NET.Sdk.Web → web-api or blazor-app
  - Microsoft.NET.Sdk.Worker → worker-service
  - Microsoft.NET.Sdk → class-library
  - Multiple projects with inter-module references → modular-monolith
  - If ambiguous, ask the user

→ If NO solution/project found (greenfield):
  - Ask: "What are you building?"
    - REST API / microservice → web-api
    - Blazor application → blazor-app
    - Background worker / queue processor → worker-service
    - NuGet package / shared library → class-library
    - Multi-module system → modular-monolith
  - Ask: "Project name?"
  - Scaffold the solution structure:
    - dotnet new sln -n ProjectName --format slnx   (modern XML solution format)
    - dotnet new webapi / worker / classlib as appropriate
    - Set up Directory.Build.props with .NET 10 defaults
    - Create src/ and tests/ folder structure
分析当前目录,判断是现有项目还是全新项目:
→ 查找.slnx / .sln文件
→ 若找到,扫描.csproj文件以确定SDK类型:
  - Microsoft.NET.Sdk.Web → web-api 或 blazor-app
  - Microsoft.NET.Sdk.Worker → worker-service
  - Microsoft.NET.Sdk → class-library
  - 存在模块间引用的多项目 → modular-monolith
  - 若无法确定,询问用户

→ 若未找到解决方案/项目(全新项目):
  - 询问:「你要构建什么类型的项目?」
    - REST API / 微服务 → web-api
    - Blazor应用 → blazor-app
    - 后台服务 / 队列处理器 → worker-service
    - NuGet包 / 共享类库 → class-library
    - 多模块系统 → modular-monolith
  - 询问:「项目名称?」
  - 搭建解决方案结构:
    - dotnet new sln -n ProjectName --format slnx   (现代XML解决方案格式)
    - 根据需求创建webapi / worker / classlib项目
    - 配置带有.NET 10默认设置的Directory.Build.props
    - 创建src/和tests/文件夹结构

Step 2: Architecture Questionnaire

步骤2:架构问卷

Load the
architecture-advisor
skill and ask targeted questions:
  1. Domain complexity — CRUD-heavy, moderate business rules, or rich domain?
  2. Team size — Solo, small team, or large team?
  3. Module boundaries — Single deployable or multiple bounded contexts?
  4. Existing patterns — (existing projects only) Detect conventions via
    convention-learner
    skill
→ Recommend: VSA, Clean Architecture, DDD, or Modular Monolith with rationale.
加载
architecture-advisor
技能并提出定向问题:
  1. 领域复杂度 — 以CRUD为主、中等业务规则还是复杂领域逻辑?
  2. 团队规模 — 单人、小型团队还是大型团队?
  3. 模块边界 — 单一可部署单元还是多个限界上下文?
  4. 现有模式 — (仅针对现有项目)通过
    convention-learner
    技能检测约定规范
→ 推荐:VSA、整洁架构、DDD或模块化单体架构,并给出理由。

Step 3: Tech Stack Selection

步骤3:技术栈选择

Ask about specific technology choices:
  • Database: PostgreSQL, SQL Server, SQLite, or none yet
  • Auth: JWT, OIDC, Cookie, or none yet
  • Caching: HybridCache, Redis, or none yet
  • Messaging: Wolverine, MassTransit, or none yet
  • Testing: Confirm xUnit + Testcontainers defaults
询问具体技术选型:
  • 数据库:PostgreSQL、SQL Server、SQLite或暂未确定
  • 认证:JWT、OIDC、Cookie或暂未确定
  • 缓存:HybridCache、Redis或暂未确定
  • 消息队列:Wolverine、MassTransit或暂未确定
  • 测试:确认xUnit + Testcontainers默认配置

Step 4: Generate CLAUDE.md

步骤4:生成CLAUDE.md

Load the appropriate template from
templates/
as a base, then customize:
  • Replace
    [ProjectName]
    with the actual project/solution name
  • Set the chosen architecture
  • Configure the tech stack section
  • For existing projects: add project-specific conventions detected in Step 2
  • For greenfield: add recommended conventions based on architecture choice
Before writing, check for an existing
CLAUDE.md
. Never overwrite it silently.
→ If ./CLAUDE.md does NOT exist:
  - Write the generated content to ./CLAUDE.md

→ If ./CLAUDE.md ALREADY exists:
  - Read it and identify hand-written / custom sections
    (anything not produced by a kit template)
  - Ask: "You already have a CLAUDE.md. How should I proceed?"
    - Merge (recommended) → keep the user's custom sections, add or refresh the
      kit's architecture, tech-stack, and convention sections in place
    - Overwrite → replace it entirely with the freshly generated file
    - Keep → leave the file untouched and print the generated content so the
      user can copy what they want by hand
  - For Merge and Overwrite: back the original up to ./CLAUDE.md.bak first.
    Never discard user content without a .bak backup.
templates/
加载合适的模板作为基础,然后进行自定义:
  • [ProjectName]
    替换为实际项目/解决方案名称
  • 设置选定的架构
  • 配置技术栈部分
  • 针对现有项目:添加步骤2中检测到的项目特定约定
  • 针对全新项目:根据架构选择添加推荐的约定
写入前需检查是否存在现有
CLAUDE.md
文件,切勿静默覆盖。
→ 若./CLAUDE.md不存在:
  - 将生成的内容写入./CLAUDE.md

→ 若./CLAUDE.md已存在:
  - 读取文件并识别手写/自定义部分
    (任何非工具模板生成的内容)
  - 询问:「你已存在CLAUDE.md文件。我应如何处理?」
    - 合并(推荐)→ 保留用户自定义部分,在原有位置添加或刷新工具生成的架构、技术栈和约定部分
    - 覆盖 → 完全替换为新生成的文件
    - 保留 → 不修改原文件,打印生成内容供用户手动复制所需部分
  - 对于合并和覆盖操作:先将原文件备份至./CLAUDE.md.bak。
    切勿在无.bak备份的情况下丢弃用户内容。

Step 5: Verify Setup

步骤5:验证设置

→ Confirm .mcp.json exists or create it (for Roslyn MCP server)
→ For existing projects:
  - Verify the solution file is discoverable
  - Run a quick health check to establish baseline
  - Report: "Project initialized. Run /health-check to see your baseline."
→ For greenfield projects:
  - Verify dotnet build succeeds on the scaffolded solution
  - Report: "Project created. Run /scaffold to add your first feature."
Skills invoked:
project-setup
,
architecture-advisor
,
convention-learner
Agent:
dotnet-architect
→ 确认.mcp.json文件是否存在,若不存在则创建(用于Roslyn MCP服务器)
→ 针对现有项目:
  - 验证解决方案文件可被识别
  - 运行快速健康检查以建立基准
  - 提示:「项目初始化完成。运行/health-check查看基准状态。」
→ 针对全新项目:
  - 验证搭建的解决方案可通过dotnet build编译
  - 提示:「项目创建完成。运行/scaffold添加首个功能。」
调用的技能:
project-setup
,
architecture-advisor
,
convention-learner
Agent:
dotnet-architect

Example — Existing Project

示例 — 现有项目

User: /dotnet-init

Claude: Detected:
  - Solution: MyApp.slnx (3 projects)
  - SDK: Microsoft.NET.Sdk.Web → Web API
  - Database: PostgreSQL (from connection string)
  - Auth: JWT (from appsettings)

  1. Domain complexity? [CRUD-heavy / Moderate / Rich domain]
  > Moderate

  2. Team size? [Solo / Small / Large]
  > Small

  Recommendation: Vertical Slice Architecture
  Generated: ./CLAUDE.md (MyApp + VSA + PostgreSQL + JWT)
  Run /health-check to see your baseline.
用户:/dotnet-init

Claude:检测到:
  - 解决方案:MyApp.slnx(3个项目)
  - SDK:Microsoft.NET.Sdk.Web → Web API
  - 数据库:PostgreSQL(来自连接字符串)
  - 认证:JWT(来自appsettings)

  1. 领域复杂度?[以CRUD为主 / 中等 / 复杂领域逻辑]
  > 中等

  2. 团队规模?[单人 / 小型 / 大型]
  > 小型

  推荐架构:垂直切片架构(Vertical Slice Architecture)
  已生成:./CLAUDE.md(MyApp + VSA + PostgreSQL + JWT)
  运行/health-check查看基准状态。

Example — Greenfield Project

示例 — 全新项目

User: /dotnet-init

Claude: No .sln or .csproj found. Let's set up a new project.

  1. What are you building? [REST API / Blazor / Worker / Library / Modular Monolith]
  > REST API

  2. Project name?
  > OrderService

  3. Domain complexity? [CRUD-heavy / Moderate / Rich domain]
  > CRUD-heavy

  Recommendation: Vertical Slice Architecture

  Creating solution...
  → dotnet new sln -n OrderService --format slnx
  → dotnet new webapi -n OrderService.Api -o src/OrderService.Api
  → dotnet new xunit3 -n OrderService.Tests -o tests/OrderService.Tests
  → Directory.Build.props with .NET 10 defaults
  → Generated: ./CLAUDE.md (OrderService + VSA + scaffold-ready)

  Run /scaffold to add your first feature.
用户:/dotnet-init

Claude:未找到.sln或.csproj文件。开始搭建新项目。

  1. 你要构建什么类型的项目?[REST API / Blazor / 后台服务 / 类库 / 模块化单体]
  > REST API

  2. 项目名称?
  > OrderService

  3. 领域复杂度?[以CRUD为主 / 中等 / 复杂领域逻辑]
  > 以CRUD为主

  推荐架构:垂直切片架构(Vertical Slice Architecture)

  正在创建解决方案...
  → dotnet new sln -n OrderService --format slnx
  → dotnet new webapi -n OrderService.Api -o src/OrderService.Api
  → dotnet new xunit3 -n OrderService.Tests -o tests/OrderService.Tests
  → 配置带有.NET 10默认设置的Directory.Build.props
  → 已生成:./CLAUDE.md(OrderService + VSA + 可搭建功能)

  运行/scaffold添加首个功能。

Example — Existing Project With a CLAUDE.md

示例 — 已存在CLAUDE.md的现有项目

User: /dotnet-init

Claude: Detected:
  - Solution: MyApp.slnx (3 projects) → Web API
  - Found an existing CLAUDE.md (custom "Deployment" and "Team conventions" sections)

  You already have a CLAUDE.md. How should I proceed?
  [Merge (recommended) / Overwrite / Keep]
  > Merge

  → Backed up original to ./CLAUDE.md.bak
  → Kept your Deployment + Team conventions sections
  → Refreshed architecture (VSA), tech-stack (PostgreSQL + JWT), and convention sections
  Generated: ./CLAUDE.md
  Run /health-check to see your baseline.
用户:/dotnet-init

Claude:检测到:
  - 解决方案:MyApp.slnx(3个项目)→ Web API
  - 已找到现有CLAUDE.md文件(包含自定义的「部署」和「团队约定」部分)

  你已存在CLAUDE.md文件。我应如何处理?
  [合并(推荐) / 覆盖 / 保留]
  > 合并

  → 已将原文件备份至./CLAUDE.md.bak
  → 保留了你的「部署」+「团队约定」部分
  → 刷新了架构(VSA)、技术栈(PostgreSQL + JWT)和约定部分
  已生成:./CLAUDE.md
  运行/health-check查看基准状态。

Related

相关命令

  • /plan
    — Plan before building features
  • /health-check
    — Assess project health after init
  • /scaffold
    — Scaffold features using the chosen architecture
  • /plan
    — 构建功能前进行规划
  • /health-check
    — 初始化后评估项目健康状态
  • /scaffold
    — 使用选定的架构搭建功能