3

so i was trying to run a really basic C# program on vscode, here's the code:

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            string Name;
            Console.Write("Input your username:\n");    
            Console.Write("u/");
            Name = Console.ReadLine();
            Console.Write("\nSo your username is u/" + Name);
        }
    }
}

And naturally, it outputs:

Input your username:

u/

Except that i can't type anything next to the "u/", not even below. it doesn't even freeze, popup an error or something like that, it just shows nothing.

and the same problem happens with C and C++. any tip?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35

1 Answers1

0
Solutions

This problem is solved in two steps:

  1. Adding Developer Command Prompt to Visual Studio Code
  2. Updating "console" field in the launch.json file.

1. Adding Developer Command Prompt to Visual Studio Code

If you create C# programs with the terminal or powershell that comes with Visual Studio Code, you will be using the old toolkit. In this case, launch.json and tasks.json files aren't created in the .vscode directory when you compile the project, and you cannot use the new features of the C# programming language through the old toolset (only C# 5.0 is supported). To add a new terminal to Visual Studio Code, use the Control Shift P shortcut and enter the command "Terminal: Select Default Profile". Click on the settings icon of any default terminal on the window that opens and name the new terminal profile "Developer Command Prompt".

enter image description here

To check that the operation was successful, use the Control Shift P shortcut to view the new terminal listed and enter the command "Terminal: Select Default Profile".

enter image description here

Use the Control Shift P shortcut and enter the "Preferences: Open Setting (JSON)" command to open the setting.json file. You can view the newly added terminal information named "Developer Command Prompt" under "terminal.integrated.profiles.windows" settings. Update this field below:

"Developer Command Prompt": {
   "path": [
      "${env:windir}\\Sysnative\\cmd.exe",
      "${env:windir}\\System32\\cmd.exe"
   ],
   "args": [
      "/K",
      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\Tools\\VsDevCmd.bat",
   ],
   "icon": "terminal-cmd"
}

Open "Developer Command Prompt" and create new project:

> mkdir TestProject
> cd TestProject
> dotnet new console

To receive data input from the console while debugging, change the configuration in the launch.json file as follows:

"console": "integratedTerminal"

When you press the F5 button to debug the opened project, a panel will open to select the environment. Select ".NET 5+ and .NET Core" from this field. In this step, the .vscode directory (launch.json and task.json files) will be created.

enter image description here

Accept all suggestions by following the prompts at the bottom right of Visual Studio Code as the new toolset will be used for the first time on the system. At this stage, launch.json and task.json files will be created under the .vscode directory.

enter image description here


2. Updating "console" Field In The launch.json

To receive data input from the console while debugging, change the configuration in the launch.json file as follows:

"console": "integratedTerminal"

3. Debugging On Test Project

Press F5 to debug the project:

enter image description here


References
Sercan
  • 4,739
  • 3
  • 17
  • 36