Run a C# Project in Visual Studio Code

This procedure walks you through running a C# console program in Visual Studio Code using the terminal.

Prerequisites#

Steps#

  1. Open Visual Studio Code with your project folder open.
  2. Open the built-in terminal with Ctrl+\`` (Windows/Linux) or Cmd+`` (Mac). You can also go to View → Terminal.
  3. Make sure the terminal is in your project folder — you should see the folder name in the terminal prompt. If not, navigate to it with cd folder-name.
  4. Save any unsaved changes with Ctrl+S (Windows/Linux) or Cmd+S (Mac).
  5. Run the program with:
dotnet run

Result#

The program builds and runs. Its output appears in the terminal directly below the dotnet run command.

For example, a program with Console.WriteLine("Hello, World!") will produce:

Hello, World!

If the build fails, the terminal will show error messages instead of output. Read the first error message — it will tell you the file name and line number where the problem is.

Common Mistakes#

Forgetting to save before running dotnet run compiles the files on disk, not what’s currently in the editor. If you’ve made changes but haven’t saved, the program will run the previous version. Always save with Ctrl+S (Windows/Linux) or Cmd+S (Mac) before running.

Running from the wrong folder dotnet run must be executed from the folder that contains the .csproj file. If the terminal is in a parent folder or subfolder, the command will fail with an error like Couldn't find a project to run. Use cd folder-name to navigate into the correct folder.

Confusing the play button with dotnet run VS Code has a play button in the top-right corner of the editor that also runs your program. Both work, but they behave slightly differently in some configurations. Using dotnet run in the terminal is more predictable and consistent.

Resources#