To read input whilst debugging, you can use the console
property in your configurations in launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/bin/Debug/net5.0/your-project-name.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "integratedTerminal"
}
]
}
You can either use "externalTerminal"
or "integratedTerminal"
. The "internalConsole"
doesn't appear to be working.
I use the integratedTerminal
setting, as the terminal is inside VSCode itself. You will now be able to read input with Console.ReadLine();
Note: Also, internalConsole
doesn't work, and it is by design. The reason this is, is because internalConsole
uses the Debug Console tab to show the output of the Console.WriteLine. Since the input box in the Debug Console is used to run expression on the current stack, there's no place to pass in input that will go to Console.ReadLine. That's the reason you'll have to use something like integratedTerminal
.
The screenshot below shows that the VSCode team knows this -
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…