This procedure walks you through running a C# console program in Visual Studio Code using the terminal.
Prerequisites#
- Visual Studio Code installed with C# Dev Kit
- A C# project created in VS Code
Steps#
- Open Visual Studio Code with your project folder open.
- Open the built-in terminal with
Ctrl+\`` (Windows/Linux) orCmd+`` (Mac). You can also go to View → Terminal. - 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. - Save any unsaved changes with
Ctrl+S(Windows/Linux) orCmd+S(Mac). - Run the program with:
dotnet runResult#
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.