C# programming with Visual Studio Code (2024)

The C# support in Visual Studio Code is optimized for cross-platform .NET development (see working with .NET and VS Code for another relevant article). Our focus with VS Code is to be a great editor for cross-platform C# development by providing a rich C# editing experience, AI-powered development, solution management, and integrated testing experiences

C# programming with Visual Studio Code (1)

VS Code supports debugging of C# applications running on either .NET or Mono.

For detailed instructions on:

  • .NET debugging - see the C# Dev Kit debugging documentation.
  • Mono debugging - see the Mono Debug extension's README.

Installing C# support

C# language support is provided with the C# Dev Kit extension. You can install it from within VS Code by searching for 'C# Dev Kit' in the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) or if you already have a project with C# files, VS Code will prompt you to install the extension as soon as you open a C# file.

For more information about the C# Dev Kit extension, see the C# documentation.

C# Dev Kit

Visual Studio Code uses the power of Roslyn and C# Dev Kit to offer an enhanced C# experience. We offer support for:

  • .NET projects
  • MSBuild projects
  • C# scripts (CSX)

Supported .NET project types include:

  • ASP.NET Core App
  • ASP.NET Core Web API
  • ASP.NET Core MVC Web App
  • Blazor Web App
  • Blazor Server App
  • Blazor WebAssembly App
  • Console App

And more.

To find a full list of supported project types within VS Code, open the Command Palette and search for .NET: New Project... This will display a full list of supported project types.

C# programming with Visual Studio Code (2)

When you open a Workspace that contains .NET solution files or project files, the Solution Explorer will automatically appear. If you have a single solution file (.sln file) in the workspace, the Solution Explorer will detect that file and automatically load it after the workspace is loaded. For more information on managing your C# projects in VS Code, look at the documentation on Project Management.

Editing Evolved

There is a lot to discover with C# and the editor, such as format on type, IntelliSense, the rename-refactoring, etc.

C# programming with Visual Studio Code (3)

For more information on the C# Dev Kit editing features, go to the Navigate and Edit documentation. For a full description of VS Code editing features, go to the Basic Editing and Code Navigation documentation.

Here are a few highlights...

IntelliSense

IntelliSense just works: hit ⌃Space (Windows, Linux Ctrl+Space) at any time to get context specific suggestions.

C# programming with Visual Studio Code (4)

Enhance completions with AI

GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates.

GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, and it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++.

You can learn more about how to get started with Copilot in the Copilot documentation.

Snippets for C#

For information on snippets in C# Dev Kit, go to the Navigate and Edit documentation. There are also several built-in snippets included in VS Code that will come up as you type or you can press ⌃Space (Windows, Linux Ctrl+Space) (Trigger Suggest) and we will give you a context specific list of suggestions.

C# programming with Visual Studio Code (6)

Tip: You can add in your own User Defined Snippets for C#. Take a look at User Defined Snippets to find out how.

Search for Symbols

There are also features outside the editor. One is the ability to search for symbols from wherever you are. Hit ⌘T (Windows, Linux Ctrl+T), start typing, and see a list of matching C# symbols. Select one and you'll be taken straight to its code location.

C# programming with Visual Studio Code (7)

CodeLens

Another cool feature is the ability to see the number of references to a method directly above the method. Click on the reference info to see the references in the Peek view. This reference information updates as you type.

Note: Methods defined in object, such as equals and hashCode do not get reference information due to performance reasons.

C# programming with Visual Studio Code (8)

Tip: You can turn off references information displayed in CodeLens with the editor.codeLens setting.

Find References/Peek Definition

You can click on the references of an object to find the locations of its use in place without losing context. This same experience works in reverse where you can Peek the definition of an object and see it inline without leaving your location. For information on Peek Definition in C# Dev Kit, go to the Navigate and Edit documentation.

C# programming with Visual Studio Code (9)

Quick Fixes / Suggestions

There are some basic quick fixes supported in VS Code. You will see a lightbulb and clicking on it, or pressing ⌘. (Windows, Linux Ctrl+.) provides you with a simple list of fixes/suggestions.

C# programming with Visual Studio Code (10)

Testing

The extension supports the following test frameworks:

The C# Dev Kit extension provides the following features:

  • Run/Debug tests cases
  • View test report
  • View tests in Testing Explorer

For more information, go to our Testing documentation for C# Dev Kit.

Next steps

Read on to find out about:

  • C# Dev Kit documentation
  • .NET Development - get up and running with cross-platform .NET
  • Basic Editing - Learn about the powerful VS Code editor.
  • Tasks - Use tasks to build your project and more.
  • Debugging - Find out how to use the debugger with your project.
  • Unity development - Learn about using VS Code with your Unity projects.

6/6/2023

C# programming with Visual Studio Code (2024)

FAQs

Is VS Code enough for C#? ›

With Visual Studio Code running, you're ready to install the C# Dev Kit. If you're working on cross-platform UI, you can install Microsoft's MAUI plug-in to use the next generation of Xamarin forms (note that MAUI is still under development).

Is it possible to use C# in Visual Studio Code? ›

C# language support is provided with the C# Dev Kit extension. You can install it from within VS Code by searching for 'C# Dev Kit' in the Extensions view (Ctrl+Shift+X) or if you already have a project with C# files, VS Code will prompt you to install the extension as soon as you open a C# file.

Is Visual Studio better than Visual Studio Code for C#? ›

Choosing between Visual Studio and Visual Studio Code refers to your specific project needs and personal preferences. Visual Studio, highlighting the Visual Studio vs Visual Studio Code difference, is ideal for comprehensive development projects, especially in languages like C#, C++, or Python.

What are the disadvantages of VS Code? ›

VS Cons. Setup Required: Unlike Visual Studio, VS Code requires manual setup for compilers, debuggers, and language-specific features. Reliance on Plugins: You need to install plugins for basic functionalities like IntelliSense, syntax highlighting, and debugging.

Is VS Code enough for coding? ›

Whether you're writing JavaScript, Python, C++, or any other language, VS Code offers a smooth coding experience. With tools for debugging, version control with Git, and customization options, it's designed to make coding efficient and enjoyable.

Can I run C# code without Visual Studio? ›

You can create new projects just like you would through Visual Studio, you just have to do it using the CLI. If you're needing it for work, but don't have a license, just have your work pay for the license, it's as simple as that. You need a license to use the VS Code .

Can I run C# in Visual Studio? ›

Open Visual Studio, and select Create a new project in the Start window. In the Create a new project window, select All languages, and then choose C# from the dropdown list. Choose Windows from the All platforms list, and choose Console from the All project types list.

Is Visual Studio the best IDE for C#? ›

For C# software development, Visual Studio Code is one of the most popular IDEs used by programmers. This is an open-source text editor and IDE developed by Microsoft. It has built-in support for languages like C#, Typescript, JavaScript, and Node.

Does C# need a compiler? ›

C# is a compiled language. C# is a managed code language, which makes it slower than an unmangaed language like C or C++.

What can Visual Studio do that VS Code Can't? ›

Visual Studio is an integrated development environment (IDE) and Visual Studio Code is a rich text editor like Sublime Text and Atom. But the difference between the tools is more than just IDE and text editor. An IDE is a robust tool for writing, editing, debugging, and running your code.

Do I need VS Code if I have Visual Studio? ›

If your needs gravitate more towards . net development or C#, you should be looking forward to using Visual Studio. IDE will be excellent for your requirements. However, if your needs gravitate towards cross-stack development, you should be using Visual Studio Code.

Should I use C# or Visual Basic? ›

In terms of event handling, writing code, auto-correction of techniques, and interoperability, VB.NET is a winner in the game of C# vs VB.NET. But all this doesn't make C# any less of a phenomenal language for building applications on the . NET framework.

What is better than VS Code? ›

The best overall Visual Studio Code alternative is Notepad++. Other similar apps like Visual Studio Code are Sublime Text, UltraEdit, Atom, and Brackets. Visual Studio Code alternatives can be found in Text Editor Software but may also be in Web Design Software. Have you used Visual Studio Code before?

Is VS Code worth learning? ›

If you prefer a lighter option, VSCode is an excellent choice. However, if memory constraints are a concern, it's worth noting that PyCharm may require more resources due to its more robust nature. Nevertheless, for beginners, PyCharm provides a more intuitive experience.

Is VS Code still used? ›

In the Stack Overflow 2023 Developer Survey, Visual Studio Code was ranked the most popular developer environment tool among 86,544 respondents, with 73.71% reporting that they use it.

What is required to run C# code? ›

You need the . NET Framework and an IDE (integrated development environment) to work with the C# language. The . NET Framework platform of the Windows OS is required to write web and desktop-based applications using not only C# but also Visual Basic and Jscript, as the platform provides language interoperability.

Is Visual Studio Code good for C programming? ›

You can make VS Code very powerful like an IDE using a lot of extensions. Before approaching the process of running your first C or C++ code on Visual Studio Code, let me guide you through the process and get it all set up based on the operating system you are using on your computer.

Top Articles
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 5999

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.