Setting Up Visual Studio Code For C++



Lately I have been using my Mac as my main daily driver. I still spin up Parallels from time to time when I need to do something inside Visual Studio, but for most of my C# work I use VS Code (and .NET Core). This blog post contain some notes about using VS Code for your C# and .NET Core development which may make your life easier.

  1. How To Code C In Visual Studio
  2. Vscode C++ Config
  3. Set Up Visual Studio Code For C++
  4. Visual Studio Code C++ Setup

As a side note, I have also actually started looking seriously into JetBrains Rider as I miss the powerful refactoring capabilities from Resharper.

  1. Setting Up Visual Studio Code Setting Up Visual Studio Code The recommended development environment for C programming in CPTR 124 and CPTR 318 this semester is Microsoft's Visual Studio Code (VSCode). VSCode is available for free for Microsoft Windows, Apple macOS, and Linux.
  2. Install the Code Runner Extension Open your C code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will be compiled and run, and the output will be shown in the Output Window.

Installation

Installation of VS Code and the .NET Core command line tools are pretty straight forward and many resources are available. For installing VS Code you can refer to the Setup section of the official documentation. It provides step-by-step instructions for Windows, Linux and Mac.

Setting up Visual Studio Code. Getting up and running with Visual Studio Code is quick and easy. It is a small download so you can install in a matter of minutes and give VS Code a try. VS Code is a free code editor, which runs on the macOS, Linux, and Windows operating systems. Follow the platform-specific guides below: macOS.

For dowbloading the .NET Core SDK you can refer to the Download section of the .NET website. You can also refer to the Get Started with .NET Core document which contains more detailed steps. It also contains a nice video walkthrough of installing both VS Code and .NET Core.

Documentation

The Visual Studio website contains pretty amazing documentation which will help you get started with the basics of using the editor. Also refer to Working with C# to get a better understanding of the C# support inside VS Code.

Extensions

Out of the box, VS Code has very limited support for C#. It does however allow you to enrich the standard functionality by installing extensions. You can discover extensions either from inside VS Code, or from the Visual Studio Code Marketplace.

The VS Code Extension Marketplace document contains more information about how to install extensions. Also refer to Using Extensions in VS Code which contains a video walktrough of installing extensions.

Below are some extensions I recommend you install to get the most from VS Code for C# (and ASP.NET Core) development.

Extensions for C

  • C#. This extension adds Syntax Highlighting, Intellisense, Go To Definition, Find All References, etc. It also add debugging support for C# applications.

    For Debugging I also suggest you refer to Instructions for setting up the .NET Core debugger

  • C# Extensions. This adds functionality to easily add a new C# class or Interface. This is useful because just creating a new file inside VS Code simply creates an empty file. This extension creates a new file for a class or interface for you, and also sets up the correct namespace for your project, as well as include the basic import statements.
  • C# Snippets. Contains many useful C# code snippets.
  • C# XML Documentation Comments. Makes adding XML comments to your code a much more pleasant experience.

Extensions for ASP.NET Core

Studio
  • ASP.NET Core Snippets. Contains snippets for easily constructing ASP.NET Core Controllers and Actions.
  • WilderMinds’ ASP.NET Core Snippets. An alternative to the ASP.NET Core Snippets extension adding a very similar set of snippets.
  • ASP.NET Helper. Adds Intellisense inside Razor view pages.
  • HTML Snippets. Adds support for HTML syntax highlighting, as well as HTML snippets.

    BTW, VS Code also includes amazing built-in Emmet support inside VS Code, which makes coding of HTML much faster.

  • IntelliSense for CSS class names. Provides CSS class name completion for the HTML class attribute based on the CSS class definitions in your project.

How To Code C In Visual Studio

Others

  • Git Extension Pack. If you are using Git, then this is an Extension Pack which installs 5 different extensions which adds a lot of very useful Git capabilities to VS Code (over and above what is already built in).
  • Darcula Theme. My favourite VS Code theme.
Vscode c++ setup

Vscode C++ Config

Refactoring

Set Up Visual Studio Code For C++

One major pain point coming from Visual Studio (and Resharper) is the lack of proper code refactoring tools. There is however some hope, as you can - with some manual effort - get some of the Visual Studio Roslyn-based refactoring extensions to work inside VS Code.

Visual Studio Code C++ Setup

For more information on how to do this, please refer to Using Roslyn refactorings with OmniSharp and Visual Studio Code by Filip W. It is not a perfect solution, but it is a good start.