Claude Code for .NET Developers: From Zero to Productive in VS Code and Visual Studio

Claude Code for .NET Developers: From Zero to Productive in VS Code and Visual Studio

Claude Code for .NET Developers: From Zero to Productive in VS Code and Visual Studio

面向 .NET 开发者的 Claude Code:从零开始到在 VS Code 和 Visual Studio 中实现高效开发

Here is the pattern that plays out constantly with AI coding tools: you try one, it blows your mind. You use it for a week, and it starts feeling random. Sometimes it’s brilliant; sometimes it confidently suggests code from three framework versions ago. You stop trusting it, and it fades into the “cool but not practical” category. The problem is not the model. The problem is that you are using a powerful tool without understanding how it works. AI 编程工具总是遵循这样一个规律:你试用一个,它让你惊艳。用了一周后,你开始觉得它表现不稳定。有时它表现出色;有时它却自信地给出三个框架版本之前的代码建议。你不再信任它,它也就沦为了“看起来很酷但不实用”的工具。问题不在于模型,而在于你在不了解其工作原理的情况下使用了一个强大的工具。

Claude Code is different from a chat window, and once you understand its mechanics — how it discovers context, how you shape its behavior, how you extend it with custom commands — it becomes genuinely reliable for .NET work. This article covers everything: installation, VS Code integration, the honest story about Visual Studio 2022 and 2026, CLAUDE.md (the most important file you are not writing yet), context management, Skills, and MCP. Whether you are new to AI tooling or already use it daily, there is something here for you. Claude Code 与聊天窗口不同。一旦你理解了它的机制——它是如何发现上下文的、你如何塑造它的行为、以及如何通过自定义命令扩展它——它就会成为 .NET 开发中真正可靠的助手。本文涵盖了所有内容:安装、VS Code 集成、关于 Visual Studio 2022 和 2026 的真实情况、CLAUDE.md(你还没开始写但最重要的文件)、上下文管理、技能(Skills)和 MCP。无论你是 AI 工具的新手还是日常使用者,本文都能为你提供帮助。

What Is Claude Code, Exactly?

究竟什么是 Claude Code?

Claude Code is not a chatbot that happens to know about code. It is a CLI-first, agentic coding assistant built by Anthropic. The key distinction: it operates on your actual repository. It can read files, run commands, edit code, and chain multiple steps together without you narrating every move. Claude Code 并不是一个恰好懂代码的聊天机器人。它是 Anthropic 构建的以 CLI(命令行界面)为核心的代理式编程助手。关键区别在于:它直接在你的实际代码仓库上运行。它可以读取文件、运行命令、编辑代码,并将多个步骤串联起来,而无需你事无巨细地进行指挥。

The mental model that helps most: Claude Code is a skilled contractor who just walked into your codebase. Give them the right context, and they can work independently. Give them nothing, and they will ask questions — or worse, make assumptions. 最有效的思维模型是:Claude Code 就像一位刚走进你代码库的熟练承包商。给它正确的上下文,它就能独立工作;什么都不给,它就会不断提问——或者更糟,做出错误的假设。

There are two surfaces you will use: 你将使用两个界面:

  • The CLI (claude) — runs in any terminal, works with any editor
  • CLI (claude) —— 在任何终端运行,适用于任何编辑器
  • The VS Code extension (anthropic.claude-code) — embeds the CLI experience directly into VS Code, with file awareness, selection sharing, and inline diffs
  • VS Code 扩展 (anthropic.claude-code) —— 将 CLI 体验直接嵌入 VS Code,具备文件感知、选区共享和内联差异对比功能

Both use the same model and the same context system. The extension is additive convenience on top of the CLI, not a separate product. 两者使用相同的模型和上下文系统。该扩展是在 CLI 之上的附加便利功能,而非独立产品。

Installation and Setup

安装与设置

Prerequisites 先决条件 You need Node.js 22 LTS or later. Check with: node --version 你需要 Node.js 22 LTS 或更高版本。通过 node --version 进行检查。

Install Claude Code globally: 全局安装 Claude Code: npm install -g @anthropic-ai/claude-code

Authenticate: 身份验证: claude The first run opens a browser for OAuth with your Anthropic account. After that, your credentials are stored locally and the CLI works offline-first (the model calls still go to Anthropic’s API, of course). 首次运行会打开浏览器进行 Anthropic 账号的 OAuth 认证。之后,凭据会存储在本地,CLI 优先离线工作(当然,模型调用仍会发送到 Anthropic 的 API)。

VS Code Integration

VS Code 集成

Install the extension from the marketplace. The ID is anthropic.claude-code. You need VS Code 1.98 or later. Once installed, a Claude icon appears in the activity bar. Open it, sign in, and you have a chat panel that is deeply aware of your open files, your current selection, and your workspace structure. 从市场安装扩展,ID 为 anthropic.claude-code。你需要 VS Code 1.98 或更高版本。安装后,活动栏会出现一个 Claude 图标。打开并登录,你将拥有一个深度感知你打开的文件、当前选区和工作区结构的聊天面板。

You can also invoke it inline with Ctrl+Shift+C (Windows/Linux) or Cmd+Shift+C (Mac) to open a quick input without leaving your editor flow. The extension does something important automatically: when you highlight code and ask a question, it attaches that selection as context. You do not have to copy-paste. This alone saves significant friction on large codebases. 你还可以通过 Ctrl+Shift+C (Windows/Linux) 或 Cmd+Shift+C (Mac) 在行内调用它,无需离开编辑器流程即可打开快速输入框。该扩展会自动执行一项重要操作:当你高亮代码并提问时,它会自动将该选区作为上下文附加。你无需手动复制粘贴。仅此一点就能显著减少在大型代码库中操作的阻力。

If you use JetBrains Rider, there is also full Claude Code integration available through the JetBrains Marketplace. The experience is comparable to VS Code. Rider users are covered — you can follow this entire article and apply it directly. 如果你使用 JetBrains Rider,JetBrains 市场也提供了完整的 Claude Code 集成。体验与 VS Code 相当。Rider 用户完全可以使用——你可以直接参考本文并应用。

Visual Studio 2022 and 2026: The Honest Story

Visual Studio 2022 和 2026:真实情况

Visual Studio has been the king of .NET IDEs for decades — it just has not heard of Claude yet. As of June 2026, there is no official Claude Code extension for Visual Studio 2022 or 2026. GitHub Copilot has deep VS integration; Claude Code does not. This is not a temporary oversight — the extension model for Visual Studio is substantially different from VS Code, and Anthropic has focused on the VS Code surface. 几十年来,Visual Studio 一直是 .NET IDE 的王者,但它目前还不支持 Claude。截至 2026 年 6 月,Visual Studio 2022 或 2026 还没有官方的 Claude Code 扩展。GitHub Copilot 有深度的 VS 集成,但 Claude Code 没有。这不是暂时的疏忽——Visual Studio 的扩展模型与 VS Code 有很大不同,而 Anthropic 目前专注于 VS Code 平台。

The workaround is simple and it works well: use the integrated terminal. Open it with View > Terminal (or Ctrl+ ). Then run: claude. 变通方法很简单且效果良好:使用集成终端。通过 View > Terminal(或 Ctrl+ )打开它,然后运行 claude

Claude Code starts in your repo’s root directory. It reads everything — your .cs files, your .csproj, your appsettings.json, your CLAUDE.md. The terminal-based experience is the same CLI you would use anywhere. You lose the inline diff rendering and selection-sharing that the VS Code extension provides, but the model’s capabilities are identical. Claude Code 会在你的仓库根目录启动。它会读取所有内容——你的 .cs 文件、.csproj、appsettings.json 和 CLAUDE.md。基于终端的体验与你在任何地方使用的 CLI 相同。虽然你失去了 VS Code 扩展提供的内联差异渲染和选区共享功能,但模型的能力是完全一样的。

Practical tip: keep Visual Studio open for debugging, the designer, and refactoring tooling (where it is unmatched), and open VS Code or a terminal alongside it for Claude interactions. Many .NET developers already do this. It is not a compromise — it is using each tool for what it is best at. 实用建议:保持 Visual Studio 打开以进行调试、使用设计器和重构工具(这些方面它无可匹敌),同时打开 VS Code 或终端进行 Claude 交互。许多 .NET 开发人员已经在这样做。这不是妥协,而是让每个工具发挥其所长。

CLAUDE.md — The Brain of the Operation

CLAUDE.md — 操作的大脑

This is the most important section in the article. Every time Claude Code starts in a directory, it performs a filesystem walk. It moves upward from the current working directory, looking for CLAUDE.md files. It also lazily loads CLAUDE.md files found in subdirectories as it encounters them during work. The result is a layered context system: a root CLAUDE.md for the whole repo, and optionally per-project or per-module files for specific concerns. 这是本文最重要的部分。每当 Claude Code 在某个目录启动时,它都会执行文件系统遍历。它会从当前工作目录向上查找 CLAUDE.md 文件。在工作过程中,它还会按需加载在子目录中发现的 CLAUDE.md 文件。结果是一个分层的上下文系统:一个用于整个仓库的根目录 CLAUDE.md,以及可选的针对特定项目或模块的 CLAUDE.md 文件。

CLAUDE.md is not magic. It is just a Markdown file. But it is the file Claude reads before doing anything else. Think of it as your onboarding document for a contractor who starts fresh every session. CLAUDE.md 并不是魔法,它只是一个 Markdown 文件。但它是 Claude 在做任何事之前都会读取的文件。把它想象成你为承包商准备的入职文档,他们每次会话开始时都会阅读它。

What Claude Does NOT Know Without CLAUDE.md 没有 CLAUDE.md 时,Claude 不知道什么 Without any instruction file, Claude Code will: 如果没有指令文件,Claude Code 会:

  • Guess your build system from file structure
  • 根据文件结构猜测你的构建系统
  • Assume generic conventions
  • 假设通用的约定
  • Ask clarifying questions repeatedly
  • 反复询问澄清问题
  • Make mistakes that a three-minute onboarding would prevent
  • 犯下本可以通过三分钟入职培训就能避免的错误

With a good CLAUDE.md, Claude knows your exact dotnet commands, your test runner, your architecture decisions, your naming conventions, and any constraints specific to your project. It stops guessing and starts working. 有了好的 CLAUDE.md,Claude 就能确切地知道你的 dotnet 命令、测试运行器、架构决策、命名规范以及项目特定的任何约束。它将停止猜测,直接开始工作。

Discovery in Visual Studio: A Common Gotcha Visual Studio 中的发现:一个常见陷阱 CLAUDE.md lives at the root of your repository — the same directory as your .sln file. Visual Studio’s Solution Explorer shows files based on what is referenced in .csproj or .sln files. CLAUDE.md 位于你的仓库根目录——与你的 .sln 文件在同一目录。Visual Studio 的解决方案资源管理器是根据 .csproj 或 .sln 文件中的引用来显示文件的。