SoFunction
Updated on 2025-04-25

Step by step to create and start a C# project using VSCode

1. Install the necessary extensions

  • Open VSCode.
  • Click the extension icon on the left (or pressCtrl+Shift+X)。
  • Search and installC#Expand. This extension is provided by Microsoft and provides basic functions required for C# development, such as intelligent perception, code navigation, debugging, etc.

2. Create a project directory

  • In the file system, create a new folder, which will be your project folder. For example, you can create a name calledMyCSharpProjectfolder.

3. Open the project directory

  • In VSCode, clickFile -> Open Folder, and select the project folder you just created.

4. Initialize C# project

  • Open the integrated terminal of VSCode (clickView -> TerminalOr press `Ctrl+``).
  • In the terminal, enter the following command to create a new C# project:
dotnet new console

This will usedotnetCommand line tools create a new console application. If you want to create a Core project, you can usedotnet new webordotnet new mvcetc. Select the commands according to the specific project type.

5. Compile the project

  • Continue in the integration terminal, compile the project with the following command:
dotnet build

This command compiles the C# code into an executable or library file, depending on your project type. The compiled results will be stored inbinin the directory.

VI. Start the project

  • For console applications, use the following command to run:
dotnet run

This will execute the compiled executable file and you will see the output of the program.

7. Debugging project (optional)

  • Set a breakpoint in the code, click on the left area of ​​the code line number to set the breakpoint.
  • Click the debug icon on the left (or pressCtrl+Shift+D)。
  • In the Debug Configuration drop-down menu at the top, select.NET Core Launch (console)
  • Click the green play button to start debugging, and the program will run to the breakpoint you set. At this time, you can use the debugging toolbar to perform single steps, view variable values, etc.

Here is a simple C# console application sample code:

using System;

namespace MyCSharpProject
{
    class Program
    {
        static void Main(string[] args)
        {
            ("Hello, World!");
        }
    }
}

Code explanation

  • using System;:IntroducedSystemNamespace, which contains some basic types and functions, such asConsolekind.
  • namespace MyCSharpProject: Defines a namespace for organizing code to avoid naming conflicts.
  • class Program: Define a name calledProgramClass of  .
  • static void Main(string[] args): The entry point of the program is where the program starts to execute.
  • ("Hello, World!");:useConsoleClassicWriteLineMethod outputs text to the console.

Through the above steps, you can create, compile, and start a C# project in VSCode. As needed, you can modify the code, add more classes and files, and use more.NETFunctions and libraries.

Summarize

This is the end of this article about using VSCode to create and start a C# project. For more related content on creating and starting a C# project in VSCode, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!