Skip to main content

C# for Visual Studio Code

Introduction

This guide will help you set up your development environment for C# using Visual Studio Code. VS Code is a lightweight and powerful editor, ideal for cross-platform C# development.

Learning objectives:

  • Install .NET SDK and Visual Studio Code
  • Configure essential C# extensions
  • Optimize your workflow with tools and shortcuts

Prerequisites & Installation

Prior knowledge

  • None (beginner's guide)

Required tools

ToolVersionLinkDescription
.NET SDK6.0+dotnet.microsoft.comC# development platform
Visual Studio CodeLatestcode.visualstudio.comCode editor

Installing .NET SDK

The .NET SDK is a free, open-source development platform for building many different types of applications. It includes the C# compiler, the .NET runtime, and the ASP.NET Core runtime.

  1. Download the .NET SDK installer from the official website
  2. Run the installer and follow the instructions
  3. Verify the installation:
dotnet --version

Installing Visual Studio Code

Visual Studio Code is a free source code editor developed by Microsoft for Windows, Linux and macOS. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring.

Windows

  1. Download the installer from code.visualstudio.com

  2. Run the installer and follow the instructions

    tip

    Consider checking the "Add 'Open with Code' action to Windows Explorer context menu" option for quick access.

  3. Open Visual Studio Code

  4. Enable auto-save: File > Auto Save

MacOS

Option 1: Download

  1. Download from code.visualstudio.com
  2. Open the file and drag the Visual Studio Code icon to the Applications folder

Option 2: Homebrew

brew install --cask visual-studio-code

Configuration:

  1. Open Visual Studio Code
  2. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P)
  3. Type shell command and select Shell Command: Install 'code' command in PATH
  4. Enable auto-save: File > Auto Save

Linux

  1. Download the installer from code.visualstudio.com/download (.deb or .rpm format)

  2. Run the installer and follow the instructions

    note

    You can also check the Visual Studio Code Insiders version for more availability.

  3. Open Visual Studio Code

  4. Install command in PATH: Command Palette (Ctrl+Shift+P) → Shell Command: Install 'code' command in PATH

  5. Enable auto-save: File > Auto Save

Installing essential C# extensions

The C# extension for Visual Studio Code adds complete support for C#, including syntax highlighting, IntelliSense (code completion), and debugging.

Install the following extensions from the Extensions sidebar (Ctrl+Shift+X):

ExtensionDescriptionLink
C#Basic C# supportMarketplace
C# ExtensionsAdditional featuresMarketplace
C# Dev KitComplete tool suiteMarketplace

Advanced configuration (Bonus)

CSharpier configuration (code formatter)

Install CSharpier globally:

dotnet tool install --global csharpier

Configure format on save:

  1. Open keyboard shortcuts: Ctrl+K Ctrl+S (or Cmd+K Cmd+S on macOS) Keyboard Shortcuts

  2. Search for Format Document

  3. Set the keybinding to Ctrl+S (or Cmd+S on macOS) Format Document

  4. Open a C# file and press Ctrl+S to automatically format

tip

Automatic formatting on save saves you time and ensures consistent code across your team.

Resources