Post

C# Development with VS Code — Part 2: Developing C# Apps

C# Development with VS Code — Part 2: Developing C# Apps

Series Overview

  1. Getting Started — Installation, UI tour, Git integration
  2. Developing C# Apps (this article) — Extensions, editing, IntelliSense, NuGet packages
  3. Debugging — Breakpoints, configurations, attach to process
  4. Productivity — Keyboard shortcuts, tasks, workflow optimisation

Essential Extensions

C# Dev Kit

The cornerstone of C# development in VS Code is the C# Dev Kit extension from Microsoft. It provides:

  • IntelliSense and code completion
  • Code navigation (Go to Definition, Find References)
  • Refactoring support
  • Solution Explorer
  • Test Explorer integration
  • Build and debug assets

Open the Extensions pane (Ctrl+Shift+X / Cmd+Shift+X), search for “C# Dev Kit”, and install it:

C# extension

Note: The original “C#” extension (OmniSharp) is still available but C# Dev Kit is now Microsoft’s recommended extension. It includes the C# extension as a dependency.

C# Extensions

Also install C# Extensions by JosKreativ. This adds shortcuts for scaffolding new classes and interfaces via right-click in the Explorer — a small but significant time-saver.

The Terminal-First Workflow

VS Code doesn’t have a “File > New Project” wizard. Instead, .NET development relies on the dotnet CLI through the integrated terminal (Ctrl+`).

Create a new console project:

1
dotnet new console -o GuideDemoApp

Open it in the current VS Code window:

1
code -r GuideDemoApp

When VS Code detects a C# project, it prompts you to add build and debug assets:

Build assets prompt

Click Yes — this creates a .vscode directory with launch.json and tasks.json that enable debugging. If you miss the prompt, open the Command Palette and search for .NET: Generate Assets for Build and Debug.

The Debug pane (Ctrl+Shift+D / Cmd+Shift+D) now shows launch configurations:

Debug pane

Editing C# Code

Creating Classes

Right-click in the Explorer and select New C# Class (from the C# Extensions extension). Enter the filename — the class is scaffolded with the correct namespace automatically.

Code Snippets

Type snippet shortcuts and press Tab to expand them. The most useful ones:

SnippetExpands To
propAuto-implemented property
propfullProperty with backing field
ctorConstructor
classClass declaration
interfaceInterface declaration
for, foreachLoop structures
tryTry/catch block
cwConsole.WriteLine()

For example, type prop and press Tab:

prop snippet

The type is highlighted — start typing string to change it. Press Tab again to jump to the property name.

IntelliSense

Just like Visual Studio, VS Code shows context-aware completions after typing a dot:

IntelliSense

Hover over any symbol to see its definition. For keyboard access: Ctrl+K Ctrl+I / Cmd+K Cmd+I.

Quick Fixes

When VS Code underlines a problem with a wavy line, place your cursor on it and press Ctrl+. / Cmd+. to see available fixes:

Quick fix - add using

Common quick fixes include:

  • Adding missing using statements
  • Removing unused usings
  • Generating constructor parameters
  • Implementing interface members
  • Extracting methods or variables

Quick File Navigation

Press Ctrl+P / Cmd+P and start typing any filename. VS Code fuzzy-matches across the entire project:

Quick file open

Working with NuGet Packages

Via the Terminal

The most reliable way to add NuGet packages:

1
dotnet add package Bogus

For a visual experience, install the NuGet Gallery extension. Open it via Command Palette > NuGet: Open Gallery:

NuGet Gallery

Search for packages, view details, and click Install next to the target .csproj file.

A Complete Example

Let’s put it together. Create a DemoUser class with the New C# Class shortcut, then add properties using the prop snippet:

1
2
3
4
5
6
7
8
9
10
namespace GuideDemoApp;

public class DemoUser
{
    public string Username { get; set; } = string.Empty;
    public string Password { get; set; } = string.Empty;

    public override string ToString()
        => $"<User: {Username} / {Password}>";
}

In Program.cs, use IntelliSense to write the main logic. Use Ctrl+. to auto-import Bogus when using the Randomizer class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using Bogus;

var bogusPerson = new Person();
var user = new DemoUser
{
    Username = (bogusPerson.FirstName[0] + bogusPerson.LastName).ToLower(),
    Password = GeneratePassword()
};

Console.WriteLine(user);

static string GeneratePassword(int numChars = 4, int numDigits = 4)
{
    var randomizer = new Randomizer();
    var letters = randomizer.String(numChars, numChars, 'A', 'Z');
    var digits = randomizer.String(numDigits, numDigits, '0', '9');
    return $"{letters}-{digits}";
}

Run it:

1
dotnet run

Generated user output

Key Takeaways

  1. Install C# Dev Kit — it’s the foundation for everything: IntelliSense, debugging, testing, navigation.
  2. Learn the dotnet CLI — project creation, package management, and builds all happen through the terminal.
  3. Use code snippetsprop, ctor, cw and others save significant typing.
  4. Use Ctrl+. constantly — quick fixes for missing usings, interface implementation, and refactoring.
  5. Use Ctrl+P for file navigation — faster than clicking through the Explorer tree.

What’s Next

In Part 3: Debugging, we’ll explore breakpoints, variable inspection, debug configurations, command-line arguments, web app debugging, and attaching to running processes.

This post is licensed under CC BY 4.0 by the author.