HeQihan

HeQihan

Master C# with VS Code: A step-by-step guide to configuring your C# development environment!

Want to start C# programming but don't want to install the bulky Visual Studio? The lightweight and powerful editor VS Code can also perfectly handle C# development (actually, I'm just used to using VS Code).

Why choose VS Code for C# development?#

  • Lightweight: The VS Code installation package is small, starts quickly, and uses few resources.
  • Cross-platform: Supports various operating systems such as Windows, macOS, and Linux.
  • Powerful extensibility: A rich set of extensions can meet various development needs, including C#.

Preparation#

Before you start, you need to ensure that the following software is installed on your computer:

  1. VS Code: Go to the VS Code official website to download and install the version suitable for your operating system.
  2. .NET SDK: Go to the .NET official website to download and install the .NET SDK. Please make sure to select SDK instead of Runtime.

.NET download interface

Install C# extension in VS Code#

  1. Open VS Code.
  2. Click the "Extensions" icon on the left sidebar (it looks like four squares, so no image needed).
  3. Type "C#" in the search box.
  4. Find the extensions “C#”, “C# Dev Kit”, and “IntelliCode for C# Dev Kit”, and click the "Install" button.

Extension store

  1. After installation, click the "Reload" button to activate the extension. (If necessary)

Create your first C# project#

  1. Choose a suitable folder on your computer to store the C# project.

  2. In VS Code, click “File” -> “Open Folder” and select the folder you just created.

  3. Open the terminal in VS Code (you can open it via “Terminal” -> “New Terminal”).

  4. In the terminal, enter the following command to create a new C# console application:

    dotnet new console -o Learncs
    

    This command will create a folder named Learncs and generate a basic C# project within it.

Terminal screenshot
Terminal screenshot

  1. In VS Code, click “File” -> “Open Folder” and select the newly created Learncs folder.

View project structure#

After opening the project, you can see the following files in the explorer view:

  • Program.cs: The main entry file for the C# application.

  • MyCSharpApp.csproj: The file that contains project configuration settings.

Project structure

Run the first line of C# code provided by Microsoft#

  1. In VS Code, open the Program.cs file.

  2. You will see the following default code:

    // See https://aka.ms/new-console-template for more information
    Console.WriteLine("Hello, World!");
    

Default code

  1. If this is your first time using VS Code, you can press Ctrl + F5 to run the code.
  2. If there are conflicts with the shortcut keys, you can use the command dotnet run in the terminal to run all the code or dotnet run Program.cs.
  3. If everything goes smoothly, the terminal will print "Hello, World!"

"Hello, World!"

Congratulations#

Now, we have successfully configured the C# development environment in VS Code and run the first line of C# code. By continuously learning and practicing, you will definitely be able to develop more complex and interesting C# applications.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.