C# runs on .NET, a single cross-platform SDK that includes the compiler, runtime and CLI. This guide covers running, debugging and building C# in VS Code.

Install the .NET SDK

  • All platforms: download the SDK (not just the runtime) from dotnet.microsoft.com.
  • macOS: brew install dotnet-sdk.
  • Linux: follow Microsoft's package instructions for your distro.

Verify: dotnet --version

VS Code

Install the C# Dev Kit extension by Microsoft. It adds project management, IntelliSense, a test explorer and debugging.

Create and run a project

dotnet new console -o hello
cd hello
dotnet run

The template creates Program.cs:

Console.WriteLine("Hello, C#!");

dotnet run restores packages, builds and runs in one step.

Debug it

Open the project, set a breakpoint, and press F5 (choose ".NET"). The debugger supports stepping, watches, conditional breakpoints and hot reload.

Build and publish

dotnet build                       # compile to a DLL
dotnet publish -c Release          # produce a deployable build

dotnet publish can even produce a self-contained executable that bundles the runtime, so the target machine doesn't need .NET installed.