VSCode Version: 1.8.0
OS Version: Win10 x64
Steps to Reproduce:
Add two lines of code in Program.cs
string a = Console.ReadLine(); Console.WriteLine(a);
Switch to VS code debug window and start debugging, Debug Console window shows, and displays the first "Hello, World." output, and stops on the line of Console.ReadLine(), enter anything in the Debug Console and press Enter will be given err message of "Unable to perform this action because the process is running."
The question is how and where to enter text for Console.ReadLine() to accept during debugging, if I open a new cmd.exe and do a "dotnet run" it works fine, but in Visual Studio Code Debug Console it's not working.
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 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With