Debugging Preparation: Console Projects (C#, C++, Visual Basic, F#)
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Preparing to debug a Console project is similar to preparing to debug a Windows project, with some additional considerations such as setting command-line arguments and how to pause the app for debugging. For more information, see Debugging preparation for a Windows Form apps. Because of the similarity of all console applications, this topic covers the following project types:
C#, Visual Basic, and F# Console Application
C++ Console Application (.NET)
C++ Console Application (Win32)
A console application uses the Console window to accept input and to display output messages. To write to the Console window, your application must use the Console object instead of the Debug object. To write to the Visual Studio Output window, use the Debug object, as usual. Be sure that you know where your application is writing or you might be looking for messages in the wrong place. For more information, see Console Class, Debug Class, and Output Window.
Set command-line arguments
You might have to specify command-line arguments for your console application. For more information, see Project Settings for a C++ Debug Configuration, Project Settings for a Visual Basic Debug Configuration, or Project Settings for C# Debug Configurations.
Like all project properties, these arguments persist between debug sessions and between Visual Studio sessions. Therefore, if the console application is one that you have debugged previously, remember that there might be arguments from previous sessions entered in the <Project> Property Pages dialog box.
Start the application
When some console applications start, they run to completion and then exit. This behavior might not give you enough time to break execution and debug. To be able to debug an application, use one of the following procedures to start the application:
Set a breakpoint in your code and start your application.
Start your application using F10 (Debug > Step Over) or F11 (Debug > Step Into), and then navigate through code using other options such as Run to click.
In the code editor, right-click a line and select Run to cursor.
When you debug a console application, you might want to start the application from the command prompt rather than from Visual Studio. In that case, you can start the application from the command prompt and attach the Visual Studio debugger to it. For more information, see Attach to Running Processes.
When you start a console application from Visual Studio, the Console window sometimes appears behind the Visual Studio window. If you try to start your console application from Visual Studio and nothing seems to happen, try to move the Visual Studio window.