Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read input when debugging console in wsl2 in VS2022

I have created a console application in Visual Studio 2022 that is just the two lines WriteLine and ReadLine. When Debugging it for Windows, a console opens that shows the output and waits for the input. However, if I switch it to debugging for WSL, I get the output in the “Output” window, but I do not find any way of entering any data to stdin of the program, thus getting stuck at the readline. Is there a way of doing this? Maybe have Visual Studio open a console window instead of using the output window in Visual Studio as it does for the Windows application?

like image 957
Gorid Avatar asked Mar 18 '26 13:03

Gorid


1 Answers

Unfortunately WSL doesn't provide yet a console to read keystroke on VS2022. The better approach I could find was using the default WSL launchSettings.json for debugging before the output to found some bug and create a new setting for debugging after the output. The problem is the need of manual attach running console app to the VS2022 debugger. But at least is a workaround.

{
  "profiles": {
    "ConsoleApp": {
      "commandName": "Project"
    },
    "WSL2": {
      "commandName": "Executable",
      "executablePath": "wsl",
      "commandLineArgs": "dotnet ConsoleApp.dll [commandLineArgs]"
    },
    "WSL": {
      "commandName": "WSL2",
      "distributionName": ""
    }
  }
}
like image 66
BDisp Avatar answered Mar 20 '26 12:03

BDisp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!