Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (43 sloc) 4.22 KB
title ms.custom ms.date ms.topic dev_langs helpviewer_keywords ms.assetid author ms.author manager ms.workload
Prepare to debug console projects | Microsoft Docs
seodec18
11/04/2016
reference
CSharp
VB
FSharp
C++
debugging [Visual Studio], console applications
debugging console applications
console applications, debugging
9641f1d9-2d5a-48b1-8731-6525e8f67892
mikejo5000
mikejo
jillfra
multiple

Debugging Preparation: Console Projects (C#, C++, Visual Basic, F#)

Preparing to debug a Console project is similar to preparing to debug a Windows project, with some additional considerations. For more information, see Windows Forms Applications, and Debugging Preparation: Windows Forms Applications (.NET). 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)

    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.

    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.

Starting 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.

See Also

You can’t perform that action at this time.