Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating tutorials for C# Dev KIt #41440

Merged
merged 21 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 16 additions & 68 deletions docs/core/tutorials/debugging-with-visual-studio-code.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Debug a .NET console application using Visual Studio Code
description: Learn how to debug a .NET console app using Visual Studio Code.
ms.date: 08/30/2023
ms.date: 06/13/2024
zone_pivot_groups: dotnet-version
---
# Tutorial: Debug a .NET console application using Visual Studio Code
Expand Down Expand Up @@ -38,20 +38,6 @@ A *breakpoint* temporarily interrupts the execution of the application before th

:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set-net6.png" alt-text="Breakpoint set":::

## Set up for terminal input

The breakpoint is located after a `Console.ReadLine` method call. The **Debug Console** doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal. For this tutorial, you use the integrated terminal.

1. The project folder contains a *.vscode* folder. Open the *launch.json* file that's in the *.vscode* folder.

1. In *launch.json*, change the `console` setting from `internalConsole` to `integratedTerminal`:

```json
"console": "integratedTerminal",
```

1. Save your changes.

## Start debugging

1. Open the Debug view by selecting the Debugging icon on the left side menu.
Expand All @@ -62,11 +48,11 @@ The breakpoint is located after a `Console.ReadLine` method call. The **Debug Co

:::image type="content" source="media/debugging-with-visual-studio-code/start-debugging.png" alt-text="Start debugging":::
webreidi marked this conversation as resolved.
Show resolved Hide resolved

1. Select the **Terminal** tab to see the "What is your name?" prompt that the program displays before waiting for a response.
1. Select the **Debug Console** tab to see the "What is your name?" prompt that the program displays before waiting for a response.

:::image type="content" source="media/debugging-with-visual-studio-code/select-terminal-net6.png" alt-text="Select the Terminal tab":::
tdykstra marked this conversation as resolved.
Show resolved Hide resolved

1. Enter a string in the **Terminal** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.
1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.

Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs. The **Locals** section of the **Variables** window displays the values of variables that are defined in the currently running method.

Expand All @@ -90,8 +76,6 @@ The **Debug Console** window lets you interact with the application you're debug

:::image type="content" source="media/debugging-with-visual-studio-code/continue-debugging.png" alt-text="Continue debugging":::
tdykstra marked this conversation as resolved.
Show resolved Hide resolved

1. Select the **Terminal** tab again.

The values displayed in the console window correspond to the changes you made in the **Debug Console**.

:::image type="content" source="media/debugging-with-visual-studio-code/changed-variable-values.png" alt-text="Terminal showing the entered values":::
Expand Down Expand Up @@ -120,7 +104,7 @@ The program displays the string that the user enters. What happens if the user d

1. Start the program with debugging by pressing <kbd>F5</kbd>.

1. In the **Terminal** tab, press the <kbd>Enter</kbd> key when prompted to enter your name.
1. In the **Debug Console** tab, press the <kbd>Enter</kbd> key when prompted to enter your name.

Because the condition you specified (`name` is either `null` or <xref:System.String.Empty?displayProperty=nameWithType>) has been satisfied, program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs.

Expand All @@ -134,7 +118,7 @@ The program displays the string that the user enters. What happens if the user d

1. Select the **Continue** button on the toolbar to continue program execution.

1. Select the **Terminal** tab, and press any key to exit the program and stop debugging.
1. Press any key to exit the program and stop debugging.

1. Clear the breakpoint by clicking on the dot in the left margin of the code window. Other ways to clear a breakpoint are by pressing <kbd>F9</kbd> or choosing **Run > Toggle Breakpoint** from the menu while the line of code is selected.

Expand Down Expand Up @@ -168,7 +152,7 @@ Visual Studio Code also allows you to step line by line through a program and mo

1. Respond to the prompt by entering a string in the Terminal tab and pressing <kbd>Enter</kbd>.

The **Terminal** tab might not display the string you enter while you're entering it, but the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method will capture your input.
The **Debug Console** tab might not display the string you enter while you're entering it, but the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method will capture your input.

1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.

Expand All @@ -186,8 +170,6 @@ Visual Studio Code also allows you to step line by line through a program and mo

:::image type="content" source="media/debugging-with-visual-studio-code/step-out.png" alt-text="Step-Out button":::

1. Select the **Terminal** tab.

The terminal displays "Press any key to exit..."

1. Press any key to exit the program.
Expand Down Expand Up @@ -247,20 +229,6 @@ A *breakpoint* temporarily interrupts the execution of the application before th

:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set-net6.png" alt-text="Breakpoint set":::

## Set up for terminal input

The breakpoint is located after a `Console.ReadLine` method call. The **Debug Console** doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal. For this tutorial, you use the integrated terminal.

1. The project folder contains a *.vscode* folder. Open the *launch.json* file that's in the *.vscode* folder.

1. In *launch.json*, change the `console` setting from `internalConsole` to `integratedTerminal`:

```json
"console": "integratedTerminal",
```

1. Save your changes.

## Start debugging

1. Open the Debug view by selecting the Debugging icon on the left side menu.
Expand All @@ -271,11 +239,11 @@ The breakpoint is located after a `Console.ReadLine` method call. The **Debug Co

:::image type="content" source="media/debugging-with-visual-studio-code/start-debugging.png" alt-text="Start debugging":::

1. Select the **Terminal** tab to see the "What is your name?" prompt that the program displays before waiting for a response.
1. Select the **Debug Conosle** tab to see the "What is your name?" prompt that the program displays before waiting for a response.

:::image type="content" source="media/debugging-with-visual-studio-code/select-terminal-net6.png" alt-text="Select the Terminal tab":::

1. Enter a string in the **Terminal** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.
1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.

Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs. The **Locals** section of the **Variables** window displays the values of variables that are defined in the currently running method.

Expand All @@ -299,8 +267,6 @@ The **Debug Console** window lets you interact with the application you're debug

:::image type="content" source="media/debugging-with-visual-studio-code/continue-debugging.png" alt-text="Continue debugging":::

1. Select the **Terminal** tab again.

The values displayed in the console window correspond to the changes you made in the **Debug Console**.

:::image type="content" source="media/debugging-with-visual-studio-code/changed-variable-values.png" alt-text="Terminal showing the entered values":::
Expand Down Expand Up @@ -329,7 +295,7 @@ The program displays the string that the user enters. What happens if the user d

1. Start the program with debugging by pressing <kbd>F5</kbd>.

1. In the **Terminal** tab, press the <kbd>Enter</kbd> key when prompted to enter your name.
1. In the **Debug Console** tab, press the <kbd>Enter</kbd> key when prompted to enter your name.

Because the condition you specified (`name` is either `null` or <xref:System.String.Empty?displayProperty=nameWithType>) has been satisfied, program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs.

Expand All @@ -343,7 +309,7 @@ The program displays the string that the user enters. What happens if the user d

1. Select the **Continue** button on the toolbar to continue program execution.

1. Select the **Terminal** tab, and press any key to exit the program and stop debugging.
1. Press any key to exit the program and stop debugging.

1. Clear the breakpoint by clicking on the dot in the left margin of the code window. Other ways to clear a breakpoint are by pressing <kbd>F9</kbd> or choosing **Run > Toggle Breakpoint** from the menu while the line of code is selected.

Expand Down Expand Up @@ -377,7 +343,7 @@ Visual Studio Code also allows you to step line by line through a program and mo

1. Respond to the prompt by entering a string in the Terminal tab and pressing <kbd>Enter</kbd>.

The **Terminal** tab might not display the string you enter while you're entering it, but the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method will capture your input.
The **Debug Console** tab might not display the string you enter while you're entering it, but the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method will capture your input.

1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.

Expand Down Expand Up @@ -456,20 +422,6 @@ A *breakpoint* temporarily interrupts the execution of the application before th

:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set-net6.png" alt-text="Breakpoint set":::

## Set up for terminal input

The breakpoint is located after a `Console.ReadLine` method call. The **Debug Console** doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal. For this tutorial, you use the integrated terminal.

1. Open *.vscode/launch.json*.

1. Change the `console` setting from `internalConsole` to `integratedTerminal`:

```json
"console": "integratedTerminal",
```

1. Save your changes.

## Start debugging

1. Open the Debug view by selecting the Debugging icon on the left side menu.
Expand All @@ -480,11 +432,11 @@ The breakpoint is located after a `Console.ReadLine` method call. The **Debug Co

:::image type="content" source="media/debugging-with-visual-studio-code/start-debugging.png" alt-text="Start debugging":::

1. Select the **Terminal** tab to see the "What is your name?" prompt that the program displays before waiting for a response.
1. Select the **Debug Console** tab to see the "What is your name?" prompt that the program displays before waiting for a response.

:::image type="content" source="media/debugging-with-visual-studio-code/select-terminal-net6.png" alt-text="Select the Terminal tab":::

1. Enter a string in the **Terminal** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.
1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.

Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs. The **Locals** section of the **Variables** window displays the values of variables that are defined in the currently running method.

Expand All @@ -508,8 +460,6 @@ The **Debug Console** window lets you interact with the application you're debug

:::image type="content" source="media/debugging-with-visual-studio-code/continue-debugging.png" alt-text="Continue debugging":::

1. Select the **Terminal** tab again.

The values displayed in the console window correspond to the changes you made in the **Debug Console**.

:::image type="content" source="media/debugging-with-visual-studio-code/changed-variable-values.png" alt-text="Terminal showing the entered values":::
Expand Down Expand Up @@ -538,7 +488,7 @@ The program displays the string that the user enters. What happens if the user d

1. Start the program with debugging by pressing <kbd>F5</kbd>.

1. In the **Terminal** tab, press the <kbd>Enter</kbd> key when prompted to enter your name.
1. In the **Debug Console** tab, press the <kbd>Enter</kbd> key when prompted to enter your name.

Because the condition you specified (`name` is either `null` or <xref:System.String.Empty?displayProperty=nameWithType>) has been satisfied, program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs.

Expand All @@ -552,7 +502,7 @@ The program displays the string that the user enters. What happens if the user d

1. Select the **Continue** button on the toolbar to continue program execution.

1. Select the **Terminal** tab, and press any key to exit the program and stop debugging.
1. Press any key to exit the program and stop debugging.

1. Clear the breakpoint by clicking on the dot in the left margin of the code window. Other ways to clear a breakpoint are by pressing <kbd>F9</kbd> or choosing **Run > Toggle Breakpoint** from the menu while the line of code is selected.

Expand Down Expand Up @@ -586,7 +536,7 @@ Visual Studio Code also allows you to step line by line through a program and mo

1. Respond to the prompt by entering a string in the Terminal tab and pressing <kbd>Enter</kbd>.

The **Terminal** tab might not display the string you enter while you're entering it, but the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method will capture your input.
The **Debug Console** tab might not display the string you enter while you're entering it, but the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method will capture your input.

The **Variables** window shows the value returned by the call to the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method.

Expand All @@ -606,8 +556,6 @@ Visual Studio Code also allows you to step line by line through a program and mo

:::image type="content" source="media/debugging-with-visual-studio-code/step-out.png" alt-text="Step-Out button":::

1. Select the **Terminal** tab.

The terminal displays "Press any key to exit..."

1. Press any key to exit the program.
Expand Down
Loading
Loading