Skip to content

Commit 351292d

Browse files
meaghanlewisadegeo
andauthored
Update create .NET console app tutorial series to include file-based apps with Codespaces (#51321)
* Update create .NET console app to include Codespaces zone pivot * edit pass * Address Copilot feedback * add pivots and debugging steps for codespaces * clarify debugging steps * add steps for publishing with codespaces * use .net 10 for publishing * Address feedback from create a console app * fix file link * update formatting * update debugging article * more cleanup for debugging article * update publishing article * edit publish property directive sentence * resize images * Update docs/core/tutorials/with-visual-studio-code.md Co-authored-by: Andy (Steve) De George <67293991+adegeo@users.noreply.github.com> * address review feedback --------- Co-authored-by: Andy (Steve) De George <67293991+adegeo@users.noreply.github.com>
1 parent 739d0cd commit 351292d

33 files changed

+369
-64
lines changed

docs/core/tutorials/debugging-with-visual-studio-code.md

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,76 @@
11
---
22
title: Debug a .NET console application using Visual Studio Code
33
description: Learn how to debug a .NET console app using Visual Studio Code.
4-
ms.date: 10/23/2025
4+
ms.date: 01/27/2026
5+
zone_pivot_groups: code-editor-set-one
56
---
67
# Tutorial: Debug a .NET console application using Visual Studio Code
78

9+
::: zone pivot="vscode"
10+
811
This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps.
912

13+
::: zone-end
14+
15+
::: zone pivot="codespaces"
16+
17+
This tutorial introduces the debugging tools available in GitHub Codespaces for working with .NET apps.
18+
19+
::: zone-end
20+
1021
## Prerequisites
1122

1223
This tutorial works with the console app that you create in [Create a .NET console application using Visual Studio Code](with-visual-studio-code.md).
1324

14-
## Use Debug build configuration
15-
16-
*Debug* and *Release* are .NET's built-in build configurations. You use the Debug build configuration for debugging and the Release configuration for the final release distribution.
25+
## Set a breakpoint
1726

18-
In the Debug configuration, a program compiles with full symbolic debug information and no optimization. Optimization complicates debugging, because the relationship between source code and generated instructions is more complex. The release configuration of a program has no symbolic debug information and is fully optimized.
27+
A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is run.
1928

20-
By default, Visual Studio Code launch settings use the Debug build configuration, so you don't need to change it before debugging.
29+
::: zone pivot="vscode"
2130

2231
1. Start Visual Studio Code.
2332

2433
1. Open the folder of the project that you created in [Create a .NET console application using Visual Studio Code](with-visual-studio-code.md).
2534

26-
## Set a breakpoint
27-
28-
A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is run.
29-
3035
1. Open the *Program.cs* file.
3136

3237
1. Set a *breakpoint* on the line that displays the name, date, and time, by clicking in the left margin of the code window. The left margin is to the left of the line numbers. Other ways to set a breakpoint are by pressing <kbd>F9</kbd> or choosing **Run** > **Toggle Breakpoint** from the menu while the line of code is selected.
3338

3439
Visual Studio Code indicates the line on which the breakpoint is set by displaying a red dot in the left margin.
3540

36-
:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set-net6.png" alt-text="Breakpoint set":::
41+
:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set.png" alt-text="Breakpoint set":::
42+
43+
::: zone-end
44+
45+
::: zone pivot="codespaces"
46+
47+
1. Open your GitHub Codespace that you created in [Create a .NET console application using Visual Studio Code](with-visual-studio-code.md).
48+
49+
1. Open the *HelloWorld.cs* file.
50+
51+
1. Set a *breakpoint* on the line that displays the name, date, and time, by clicking in the left margin of the code window. The left margin is to the left of the line numbers. You can also set a breakpoint are by pressing <kbd>F9</kbd> while the line of code is selected.
52+
53+
:::image type="content" source="media/debugging-with-visual-studio-code/codespaces-breakpoint-set.png" alt-text="Breakpoint set":::
54+
55+
::: zone-end
3756

3857
## Start debugging
3958

59+
*Debug* and *Release* are .NET's built-in build configurations. You use the Debug build configuration for debugging and the Release configuration for the final release distribution.
60+
61+
::: zone pivot="vscode"
62+
63+
By default, Visual Studio Code launch settings use the Debug build configuration, so you don't need to change it before debugging.
64+
4065
1. Open the Debug view by selecting the Debugging icon on the left side menu.
4166

42-
:::image type="content" source="media/debugging-with-visual-studio-code/select-debug-pane-net6.png" alt-text="Open the Debug tab in Visual Studio Code":::
67+
:::image type="content" source="media/debugging-with-visual-studio-code/select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code":::
4368

4469
1. Select **Run and Debug**. If asked, select **C#** and then select **C#: Launch startup project**. Other ways to start the program in debugging mode are by pressing <kbd>F5</kbd> or choosing **Run** > **Start Debugging** from the menu.
4570

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

48-
1. If asked to **Select Launch Configuration**, select **C#: HelloWorld HelloWorld**.
73+
1. If asked to **Select Launch Configuration**, select **C#: Debug Active File**.
4974

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

@@ -55,7 +80,29 @@ A *breakpoint* temporarily interrupts the execution of the application before th
5580

5681
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.
5782

58-
:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-hit-net6.png" alt-text="Breakpoint hit, showing Locals":::
83+
:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-hit.png" alt-text="Breakpoint hit, showing Locals":::
84+
85+
::: zone-end
86+
87+
::: zone pivot="codespaces"
88+
89+
By default, GitHub Codespaces uses the Debug build configuration, so you don't need to change it before debugging.
90+
91+
1. Open the Debug view by selecting the Debugging icon on the left side menu.
92+
93+
:::image type="content" source="media/debugging-with-visual-studio-code/codespaces-select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code":::
94+
95+
1. Select **Run and Debug**. If asked, select **C#** as the debugger and then select **C#: Debug Active File** as the Launch Configuration.
96+
97+
1. Select the **Debug Console** tab to see the "What is your name?" prompt that the program displays before waiting for a response.
98+
99+
1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press <kbd>Enter</kbd>.
100+
101+
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.
102+
103+
:::image type="content" source="media/debugging-with-visual-studio-code/codespaces-breakpoint-hit.png" alt-text="Breakpoint hit, showing Locals":::
104+
105+
::: zone-end
59106

60107
## Use the Debug Console
61108

@@ -65,9 +112,9 @@ The **Debug Console** window lets you interact with the application you're debug
65112

66113
1. Enter `name = "Gracie"` at the prompt at the bottom of the **Debug Console** window and press <kbd>Enter</kbd>.
67114

68-
:::image type="content" source="media/debugging-with-visual-studio-code/change-variable-values-net6.png" alt-text="Change variable values":::
115+
:::image type="content" source="media/debugging-with-visual-studio-code/change-variable-values.png" alt-text="Change variable values":::
69116

70-
1. Enter `currentDate = DateTime.Parse("2019-11-16T17:25:00Z").ToUniversalTime()` at the bottom of the **Debug Console** window and press <kbd>Enter</kbd>.
117+
1. Enter `currentDate = DateTime.Parse("2026-01-28T20:54:00Z").ToUniversalTime()` at the bottom of the **Debug Console** window and press <kbd>Enter</kbd>.
71118

72119
The **Variables** window displays the new values of the `name` and `currentDate` variables.
73120

@@ -77,7 +124,7 @@ The **Debug Console** window lets you interact with the application you're debug
77124

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

80-
:::image type="content" source="media/debugging-with-visual-studio-code/changed-variable-values.png" alt-text="Terminal showing the entered values":::
127+
:::image type="content" source="media/debugging-with-visual-studio-code/codespaces-changed-variable-values.png" alt-text="Terminal showing the entered values":::
81128

82129
1. Press <kbd>Enter</kbd> to exit the application and stop debugging.
83130

@@ -87,15 +134,15 @@ The program displays the string that the user enters. What happens if the user d
87134

88135
1. Right-click (<kbd>Ctrl</kbd>-click on macOS) on the red dot that represents the breakpoint. In the context menu, select **Edit Breakpoint** to open a dialog that lets you enter a conditional expression.
89136

90-
:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-context-menu-net6.png" alt-text="Breakpoint context menu":::
137+
:::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-context-menu.png" alt-text="Breakpoint context menu":::
91138

92139
1. Select `Expression` in the drop-down, enter the following conditional expression, and press <kbd>Enter</kbd>.
93140

94141
```csharp
95142
String.IsNullOrEmpty(name)
96143
```
97144

98-
:::image type="content" source="media/debugging-with-visual-studio-code/conditional-expression-net6.png" alt-text="Enter a conditional expression":::
145+
:::image type="content" source="media/debugging-with-visual-studio-code/conditional-expression.png" alt-text="Enter a conditional expression":::
99146

100147
Each time the breakpoint is hit, the debugger calls the `String.IsNullOrEmpty(name)` method, and it breaks on this line only if the method call returns `true`.
101148

@@ -127,45 +174,43 @@ The program displays the string that the user enters. What happens if the user d
127174

128175
Visual Studio Code also allows you to step line by line through a program and monitor its execution. Ordinarily, you'd set a breakpoint and follow program flow through a small part of your program code. Since this program is small, you can step through the entire program.
129176

130-
1. Set a breakpoint on the opening curly brace of the `Main` method.
177+
1. Set a breakpoint on the line of code that displays the "What is your name?" prompt.
131178

132179
1. Press <kbd>F5</kbd> to start debugging.
133180

134181
Visual Studio Code highlights the breakpoint line.
135182

136183
At this point, the **Variables** window shows that the `args` array is empty, and `name` and `currentDate` have default values.
137184

138-
1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.
185+
1. Select **Step Into** from the Debug toolbar or press <kbd>F11</kbd>.
139186

140187
:::image type="content" source="media/debugging-with-visual-studio-code/step-into.png" alt-text="Step-Into button":::
141188

142189
Visual Studio Code highlights the next line.
143190

144-
1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.
145-
146-
Visual Studio Code runs the `Console.WriteLine` for the name prompt and highlights the next line of execution. The next line is the `Console.ReadLine` for the `name`. The **Variables** window is unchanged, and the **Terminal** tab shows the "What is your name?" prompt.
191+
1. Visual Studio Code runs the `Console.WriteLine` for the name prompt and highlights the next line of execution. The next line is the `Console.ReadLine` for the `name`. The **Variables** window is unchanged, and the **Terminal** tab shows the "What is your name?" prompt.
147192

148-
1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.
193+
1. Select **Step Into** or press <kbd>F11</kbd>.
149194

150-
Visual Studio highlights the `name` variable assignment. The **Variables** window shows that `name` is still `null`.
195+
Visual Studio Code highlights the `name` variable assignment. The **Variables** window shows that `name` is still `null`.
151196

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

154199
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.
155200

156-
1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.
201+
1. Select **Step Into** or press <kbd>F11</kbd>.
157202

158203
Visual Studio Code highlights the `currentDate` variable assignment. The **Variables** window shows the value returned by the call to the <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method. The **Terminal** tab displays the string you entered at the prompt.
159204

160-
1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.
205+
1. Select **Step Into** or press <kbd>F11</kbd>.
161206

162207
The **Variables** window shows the value of the `currentDate` variable after the assignment from the <xref:System.DateTime.Now?displayProperty=nameWithType> property.
163208

164-
1. Select **Run** > **Step Into** or press <kbd>F11</kbd>.
209+
1. Select **Step Into** or press <kbd>F11</kbd>.
165210

166211
Visual Studio Code calls the <xref:System.Console.WriteLine(System.String,System.Object,System.Object)?displayProperty=nameWithType> method. The console window displays the formatted string.
167212

168-
1. Select **Run** > **Step Out** or press <kbd>Shift</kbd>+<kbd>F11</kbd>.
213+
1. Select **Step Out** or press <kbd>Shift</kbd>+<kbd>F11</kbd>.
169214

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

@@ -177,15 +222,25 @@ Visual Studio Code also allows you to step line by line through a program and mo
177222

178223
Once you've tested the Debug version of your application, you should also compile and test the Release version. The Release version incorporates compiler optimizations that can affect the behavior of an application. For example, compiler optimizations that are designed to improve performance can create race conditions in multithreaded applications.
179224

225+
::: zone pivot="vscode"
226+
180227
To build and test the Release version of your console application, open the **Terminal** and run the following command:
181228

182229
```dotnetcli
183230
dotnet run --configuration Release
184231
```
185232

186-
## Additional resources
233+
::: zone-end
234+
235+
::: zone pivot="codespaces"
236+
237+
To build and test the Release version of your console application, run the following command in the terminal:
238+
239+
```dotnetcli
240+
dotnet run --configuration Release HelloWorld.cs
241+
```
187242

188-
- [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging)
243+
::: zone-end
189244

190245
## Next steps
191246

Binary file not shown.
25.1 KB
Loading
Binary file not shown.
113 KB
Loading
Binary file not shown.
74.3 KB
Loading
Binary file not shown.
66.3 KB
Loading
129 KB
Loading

0 commit comments

Comments
 (0)