Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 18 additions & 20 deletions docs/core/tutorials/debugging-with-visual-studio-code.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
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: 10/22/2021
ms.date: 11/11/2022
zone_pivot_groups: dotnet-version
recommendations: false
---
# Tutorial: Debug a .NET console application using Visual Studio Code

::: zone pivot="dotnet-7-0,dotnet-6-0"
::: zone pivot="dotnet-7-0"

This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps.

Expand Down Expand Up @@ -216,7 +216,7 @@ In this tutorial, you used Visual Studio Code debugging tools. In the next tutor

::: zone-end

::: zone pivot="dotnet-5-0"
::: zone pivot="dotnet-6-0"

This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps.

Expand All @@ -226,7 +226,7 @@ This tutorial introduces the debugging tools available in Visual Studio Code for

## Use Debug build configuration

*Debug* and *Release* are .NET Core's built-in build configurations. You use the Debug build configuration for debugging and the Release configuration for the final release distribution.
*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.

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.

Expand All @@ -238,15 +238,15 @@ By default, Visual Studio Code launch settings use the Debug build configuration

## Set a breakpoint

A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is executed.
A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is run.

1. Open the *Program.cs* file.

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.

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

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

## Set up for terminal input

Expand All @@ -266,21 +266,21 @@ The breakpoint is located after a `Console.ReadLine` method call. The **Debug Co

1. Open the Debug view by selecting the Debugging icon on the left side menu.

:::image type="content" source="media/debugging-with-visual-studio-code/select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code":::
:::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":::

1. Select the green arrow at the top of the pane, next to **.NET Core Launch (console)**. Other ways to start the program in debugging mode are by pressing <kbd>F5</kbd> or choosing **Run** > **Start Debugging** from the menu.

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

:::image type="content" source="media/debugging-with-visual-studio-code/select-terminal.png" alt-text="Select the Terminal tab":::
:::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>.

Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method executes. The **Locals** section of the **Variables** window displays the values of variables that are defined in the currently executing method.
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.

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

## Use the Debug Console

Expand All @@ -290,7 +290,7 @@ The **Debug Console** window lets you interact with the application you're debug

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

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

1. Enter `currentDate = DateTime.Parse("2019-11-16T17:25:00Z").ToUniversalTime()` at the bottom of the **Debug Console** window and press the <kbd>Enter</kbd> key.

Expand All @@ -314,25 +314,25 @@ The program displays the string that the user enters. What happens if the user d

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.

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

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

```csharp
String.IsNullOrEmpty(name)
```

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

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

Instead of a conditional expression, you can specify a *hit count*, which interrupts program execution before a statement is executed a specified number of times. Another option is to specify a *filter condition*, which interrupts program execution based on such attributes as a thread identifier, process name, or thread name.
Instead of a conditional expression, you can specify a *hit count*, which interrupts program execution before a statement is run a specified number of times. Another option is to specify a *filter condition*, which interrupts program execution based on such attributes as a thread identifier, process name, or thread name.

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.

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

The **Variables** window shows that the value of the `name` variable is `""`, or <xref:System.String.Empty?displayProperty=nameWithType>.

Expand All @@ -342,8 +342,6 @@ The program displays the string that the user enters. What happens if the user d
name == String.Empty
```

:::image type="content" source="media/debugging-with-visual-studio-code/expression-in-debug-console.png" alt-text="Debug Console returning a value of true after the statement is executed":::

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.
Expand Down Expand Up @@ -372,7 +370,7 @@ Visual Studio Code also allows you to step line by line through a program and mo

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

Visual Studio Code executes 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.
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.

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

Expand Down Expand Up @@ -427,8 +425,8 @@ In this tutorial, you used Visual Studio Code debugging tools. In the next tutor

::: zone-end

::: zone pivot="dotnet-core-3-1"
::: zone pivot="dotnet-core-3-1,dotnet-5-0"

This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page.
This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page.

::: zone-end
44 changes: 22 additions & 22 deletions docs/core/tutorials/library-with-visual-studio-code.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
title: Create a .NET class library using Visual Studio Code
description: Learn how to create a .NET class library using Visual Studio Code.
ms.date: 10/25/2021
ms.date: 11/11/2022
zone_pivot_groups: dotnet-version
recommendations: false
---
# Tutorial: Create a .NET class library using Visual Studio Code

::: zone pivot="dotnet-7-0,dotnet-6-0"
::: zone pivot="dotnet-7-0"

In this tutorial, you create a simple utility library that contains a single string-handling method.

A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 6, it can be called by any application that targets .NET 6. This tutorial shows how to target .NET 6.
A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 7, it can be called by any application that targets .NET 7. This tutorial shows how to target .NET 7.

When you create a class library, you can distribute it as a third-party component or as a bundled component with one or more applications.

## Prerequisites

* [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery).
* The [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0).
* The [.NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0).

## Create a solution

Expand Down Expand Up @@ -81,15 +81,15 @@ Add a new .NET class library project named "StringLibrary" to the solution.
Project `StringLibrary\StringLibrary.csproj` added to the solution.
```

1. Check to make sure that the library targets .NET 6. In **Explorer**, open *StringLibrary/StringLibrary.csproj*.
1. Check to make sure that the library targets .NET 7. In **Explorer**, open *StringLibrary/StringLibrary.csproj*.

The `TargetFramework` element shows that the project targets .NET 6.0.
The `TargetFramework` element shows that the project targets .NET 7.0.

```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

</Project>
Expand All @@ -114,11 +114,11 @@ Add a new .NET class library project named "StringLibrary" to the solution.
The terminal output looks like the following example:

```output
Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET
Microsoft (R) Build Engine version 16.7.4+b89cb5fde for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net6.0\StringLibrary.dll
StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net7.0\StringLibrary.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Expand Down Expand Up @@ -222,18 +222,18 @@ In this tutorial, you created a solution, added a library project, and added a c

::: zone-end

::: zone pivot="dotnet-5-0"
::: zone pivot="dotnet-6-0"

In this tutorial, you create a simple utility library that contains a single string-handling method.

A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 5, it can be called by any application that targets .NET 5. This tutorial shows how to target .NET 5.
A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 6, it can be called by any application that targets .NET 6. This tutorial shows how to target .NET 6.

When you create a class library, you can distribute it as a third-party component or as a bundled component with one or more applications.

## Prerequisites

1. [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery).
2. The [.NET 5.0 SDK or later](https://dotnet.microsoft.com/download)
* [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery).
* The [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0).

## Create a solution

Expand Down Expand Up @@ -296,27 +296,27 @@ Add a new .NET class library project named "StringLibrary" to the solution.
Project `StringLibrary\StringLibrary.csproj` added to the solution.
```

1. Check to make sure that the library targets .NET 5. In **Explorer**, open *StringLibrary/StringLibrary.csproj*.
1. Check to make sure that the library targets .NET 6. In **Explorer**, open *StringLibrary/StringLibrary.csproj*.

The `TargetFramework` element shows that the project targets .NET 5.0.
The `TargetFramework` element shows that the project targets .NET 6.0.

```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
```

1. Open *Class1.cs* and replace the code with the following code.

:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs":::
:::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/StringLibrary/Class1.cs":::

The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a <xref:System.Boolean> value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The <xref:System.Char.IsUpper(System.Char)?displayProperty=nameWithType> method returns `true` if a character is uppercase.

`StartsWithUpper` is implemented as an [extension method](../../csharp/programming-guide/classes-and-structs/extension-methods.md) so that you can call it as if it were a member of the <xref:System.String> class. The question mark (`?`) after `string` indicates that the string may be null.
`StartsWithUpper` is implemented as an [extension method](../../csharp/programming-guide/classes-and-structs/extension-methods.md) so that you can call it as if it were a member of the <xref:System.String> class.

1. Save the file.

Expand All @@ -333,7 +333,7 @@ Add a new .NET class library project named "StringLibrary" to the solution.
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net5.0\StringLibrary.dll
StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net6.0\StringLibrary.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Expand Down Expand Up @@ -375,7 +375,7 @@ Add a console application that uses the class library. The app will prompt the u

1. Open *ShowCase/Program.cs* and replace all of the code with the following code.

:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/ShowCase/Program.cs":::
:::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/ShowCase/Program.cs":::

The code uses the `row` variable to maintain a count of the number of rows of data written to the console window. Whenever it's greater than or equal to 25, the code clears the console window and displays a message to the user.

Expand Down Expand Up @@ -437,8 +437,8 @@ In this tutorial, you created a solution, added a library project, and added a c

::: zone-end

::: zone pivot="dotnet-core-3-1"
::: zone pivot="dotnet-core-3-1,dotnet-5-0"

This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page.
This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page.

::: zone-end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading