Debugging: Attach to Process for Console App running inside cmd.exe

You have some options:

  • Use "Debug -> Command line arguments" option in Visual Studio;
  • Use "Debug -> Attach to process" and find your process; it is not cmd.exe, but a process with executable name like "MyProject.exe". You can use Process Explorer or another task manager with "tree view" support to easily find the Process ID - just look for the processes started by your cmd.exe.
  • Put Debugger.Break() into your code - when this method is executed, the system will launch a dialog asking you to choose what instance of Visual Studio to use for debugging (you can choose the one with your project already open).

To debug from the command line rather than using the VS GUI maze:

  • Launch the Visual Studio Command Prompt

  • type vsjitdebugger/? which gives you the command example like :

c:> vsjitdebugger [AppName] [Args] : Launch the specified executable and attach to debugger

  • typing tlist or tasklist will give you PIDs for attaching to existing processes. example:

c:> tasklist | find /i "web"