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#? ›

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.

Which is better for C# VS Code or Visual Studio? ›

Visual Studio: Optimal for projects requiring robust Microsoft support, especially those involving languages like HTML, CSS, JavaScript, C++, Python, and JSON. It excels when developing comprehensive full-stack applications. VSCode: Ideal for those embarking on cross-stack development ventures.

How to make C# code more efficient? ›

5 ways to write faster C#
  1. Use XmlNodeReader over XPath. The XmlNodeReader and XmlTextReader will perform significantly faster than using any XPath expression. ...
  2. Use String. Compare instead of ='s. ...
  3. Avoid many calls to Guid. NewGuid() ...
  4. Use For instead of ForEach. ...
  5. Use Release Mode.

Why do people use Visual Studio for C#? ›

Visual Studio provides developers a feature rich development environment to develop high-quality code efficiently and collaboratively.

Can I learn C# in VS Code? ›

This getting started guide introduces you to C# and .NET for Visual Studio Code through the following tasks: Installing and setting up your VS Code environment for C#. Writing and running a simple "Hello World" application using C#. Introduce you to other learning resources for C# in VS Code.

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.

Why is C# so much better than Java? ›

Good performance was the motive behind the launch of C#. It is well-known that C# uses a Just-in-time compiler, which usually loads less on the CPU and responds quickly. Java also provides high performance but it uses a lot of memory usage. Due to this reason, C# is more efficient than Java.

What is the best C# extension for Visual Studio Code? ›

Here are some of my favorite extensions for C# and .NET:
  • C# Dev Kit. Microsoft's latest tools for working with . ...
  • JetBrains Rider Dark Theme. ...
  • Draw.io VS Code Integration. ...
  • Markdown All in One. ...
  • Dendron Paste Image. ...
  • Lit-html. ...
  • VS Code Import code. ...
  • Auto Rename Tag.
Nov 11, 2023

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

If you need to collaborate with team members on development or debugging, then Visual Studio is the better choice. If you need to do serious code analysis or performance profiling, or debug from a snapshot, then Visual Studio Enterprise will help you.

How can I be good at C# programming? ›

Being good at C# programming also means being good at understanding the business requirements for your code. This encompasses everything from knowing the specific input and output requirements to understanding how your code will be used in the greater context of the application.

How to write a good code in C#? ›

To write clean code, there are some tips available.
  1. Use precise names.
  2. Create self-documenting code.
  3. Functions should be compact and limited to a single task.
  4. Format code content consistently.
  5. Avoid code duplication (repetition of the same code)
  6. Code should be testable.
  7. Add comments.
  8. Adopt modular programming.
May 23, 2024

Why is C# so powerful? ›

C# is very flexible and allows you to develop a big variety of systems. With C# you maximize the return of investment on your skills because you can build almost any kind of applications: Console applications. Desktop applications (Windows Forms, WPF)

Should you use VS Code for C#? ›

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.

Can I write C# in Visual Studio Code? ›

If you are an existing VS Code user, you can add .NET support by installing the C# Dev Kit extension. C# Dev Kit brings a productive and reliable C# experience into VS Code, facilitating C# or multi-language development in VS Code.

How to get started with C# in Visual Studio? ›

Create a project
  1. Open Visual Studio, and select Create a new project in the Start window.
  2. In the Create a new project window, choose C# from the Language list. ...
  3. In the Configure your new project window, type or enter Calculator in the Project name box. ...
  4. In the Additional information window, verify that .
Mar 15, 2024

Is Visual Studio the best IDE for C#? ›

Visual Studio is one of the main heavy hitter IDEs when it comes to C#. In fact, if you ask around, you'll find that most developers will answer that they use either VS Code or Visual Studio for their C# development (for all the rest, read on in this article for the other IDEs).

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.

Can C# use C code? ›

You can directly call C functions from C# by using P/Invoke. Here's a short how-to on creating a C# lbrary that wraps around a C dll. Now in the Linker branch, go to General, and change Output File to: "$(SolutionDir)Wrapper\$(ProjectName). dll", this will copy the built C DLL to the C# project root.

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6007

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.