diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 2a1fac42e3233..c832fa0a38bd1 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -1,5 +1,55 @@ { "redirections": [ + { + "source_path": "docs/core/tutorials/with-visual-studio.md", + "redirect_url": "/dotnet/core/tutorials/create-console-app", + "redirect_document_id": false + }, + { + "source_path": "docs/core/tutorials/debugging-with-visual-studio.md", + "redirect_url": "/dotnet/core/tutorials/debug-console-app", + "redirect_document_id": false + }, + { + "source_path": "docs/core/tutorials/publishing-with-visual-studio.md", + "redirect_url": "/dotnet/core/tutorials/publish-console-app", + "redirect_document_id": false + }, + { + "source_path": "docs/core/tutorials/library-with-visual-studio.md", + "redirect_url": "/dotnet/core/tutorials/create-class-library", + "redirect_document_id": false + }, + { + "source_path": "docs/core/tutorials/testing-library-with-visual-studio.md", + "redirect_url": "/dotnet/core/tutorials/test-class-library", + "redirect_document_id": false + }, + { + "source_path": "docs/core/tutorials/with-visual-studio-code.md", + "redirect_url": "/dotnet/core/tutorials/create-console-app", + "redirect_document_id": true + }, + { + "source_path": "docs/core/tutorials/debugging-with-visual-studio-code.md", + "redirect_url": "/dotnet/core/tutorials/debug-console-app", + "redirect_document_id": true + }, + { + "source_path": "docs/core/tutorials/publishing-with-visual-studio-code.md", + "redirect_url": "/dotnet/core/tutorials/publish-console-app", + "redirect_document_id": true + }, + { + "source_path": "docs/core/tutorials/library-with-visual-studio-code.md", + "redirect_url": "/dotnet/core/tutorials/create-class-library", + "redirect_document_id": true + }, + { + "source_path": "docs/core/tutorials/testing-library-with-visual-studio-code.md", + "redirect_url": "/dotnet/core/tutorials/test-class-library", + "redirect_document_id": true + }, { "source_path": "docs/core/tools/dotnet-migrate.md", "redirect_url": "/previous-versions/dotnet/fundamentals/tools/dotnet-migrate", diff --git a/docs/core/apps.md b/docs/core/apps.md index 8c5f33369b1cb..50b294c443e9a 100644 --- a/docs/core/apps.md +++ b/docs/core/apps.md @@ -23,7 +23,7 @@ ms.custom: "updateeachrelease" ## Other app types -* [Console apps](tutorials/with-visual-studio-code.md) +* [Console apps](tutorials/create-console-app.md) * [Internet of Things (IoT)](../iot/index.yml) * [Machine learning](../machine-learning/index.yml) * [Windows services](/aspnet/core/host-and-deploy/windows-service) diff --git a/docs/core/deploying/index.md b/docs/core/deploying/index.md index 63264e3d26523..7165da1e71e00 100644 --- a/docs/core/deploying/index.md +++ b/docs/core/deploying/index.md @@ -15,13 +15,13 @@ This article explains the different ways to publish a .NET application. It cover ::: zone pivot="vscode" -For a short tutorial on publishing, see [Tutorial: Publish a .NET console application using Visual Studio Code](../tutorials/publishing-with-visual-studio-code.md). +For a short tutorial on publishing, see [Tutorial: Publish a .NET console application](../tutorials/publish-console-app.md). ::: zone-end ::: zone pivot="visualstudio" -For a short tutorial on publishing, see [Tutorial: Publish a .NET console application using Visual Studio](../tutorials/publishing-with-visual-studio.md). +For a short tutorial on publishing, see [Tutorial: Publish a .NET console application](../tutorials/publish-console-app.md). ::: zone-end diff --git a/docs/core/diagnostics/managed-debuggers.md b/docs/core/diagnostics/managed-debuggers.md index 346a446c29a00..fe049abbcc0e9 100644 --- a/docs/core/diagnostics/managed-debuggers.md +++ b/docs/core/diagnostics/managed-debuggers.md @@ -13,7 +13,7 @@ Microsoft provides debuggers for managed code in **Visual Studio** and **Visual **Visual Studio** is an integrated development environment with the most comprehensive debugger available. Visual Studio is an excellent choice for developers working on Windows. -- [Tutorial - Debugging a .NET Core application on Windows with Visual Studio](../tutorials/debugging-with-visual-studio.md) +- [Tutorial - Debugging a .NET application](../tutorials/debug-console-app.md) - [Debug ASP.NET Core apps in Visual Studio](/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications#debug-aspnet-core-apps) While Visual Studio is a Windows application, it can also be used to debug Linux apps running remotely, in WSL, or in Docker containers: @@ -26,5 +26,5 @@ While Visual Studio is a Windows application, it can also be used to debug Linux **Visual Studio Code** is a lightweight cross-platform code editor. It uses the same .NET Core debugger implementation as Visual Studio, but with a simplified user interface. -- [Tutorial - Debugging a .NET Core application with Visual Studio Code](../tutorials/debugging-with-visual-studio-code.md) +- [Tutorial - Debugging a .NET application](../tutorials/debug-console-app.md) - [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) diff --git a/docs/core/install/linux-alpine.md b/docs/core/install/linux-alpine.md index d2a115f40920b..d932a53a935f1 100644 --- a/docs/core/install/linux-alpine.md +++ b/docs/core/install/linux-alpine.md @@ -90,4 +90,4 @@ Use the `apk add` command to install the dependencies. - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-debian.md b/docs/core/install/linux-debian.md index d56a6578e1120..7c971f887a8fe 100644 --- a/docs/core/install/linux-debian.md +++ b/docs/core/install/linux-debian.md @@ -163,4 +163,4 @@ sudo apt install libc6 - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-fedora.md b/docs/core/install/linux-fedora.md index 332565cfc2e7a..4a2fa47fb3995 100644 --- a/docs/core/install/linux-fedora.md +++ b/docs/core/install/linux-fedora.md @@ -101,4 +101,4 @@ For more information about solving these problems, see [Troubleshoot `fxr`, `lib - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-opensuse.md b/docs/core/install/linux-opensuse.md index 2b4a4c33bae64..d23a42f447bb6 100644 --- a/docs/core/install/linux-opensuse.md +++ b/docs/core/install/linux-opensuse.md @@ -139,4 +139,4 @@ For more information about the dependencies, see [Self-contained Linux apps](htt - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-rhel.md b/docs/core/install/linux-rhel.md index 4063a99f846a0..a9db1b3cf31ee 100644 --- a/docs/core/install/linux-rhel.md +++ b/docs/core/install/linux-rhel.md @@ -118,4 +118,4 @@ For more information about solving these problems, see [Troubleshoot `fxr`, `lib - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-scripted-manual.md b/docs/core/install/linux-scripted-manual.md index b781569b1fcb7..340fb06a86504 100644 --- a/docs/core/install/linux-scripted-manual.md +++ b/docs/core/install/linux-scripted-manual.md @@ -253,4 +253,4 @@ Set the following two environment variables in your shell profile: - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-sles.md b/docs/core/install/linux-sles.md index d9284abe05808..5b578ed987650 100644 --- a/docs/core/install/linux-sles.md +++ b/docs/core/install/linux-sles.md @@ -138,4 +138,4 @@ For more information about the dependencies, see [Self-contained Linux apps](htt - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-snap-sdk.md b/docs/core/install/linux-snap-sdk.md index 1aeb0c5b4fd05..120fe1e34e577 100644 --- a/docs/core/install/linux-snap-sdk.md +++ b/docs/core/install/linux-snap-sdk.md @@ -233,4 +233,4 @@ The certificate location varies by distribution. Here are the locations for the - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI.](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-ubuntu-decision.md b/docs/core/install/linux-ubuntu-decision.md index 1678cb1938e3d..ddc05947404d1 100644 --- a/docs/core/install/linux-ubuntu-decision.md +++ b/docs/core/install/linux-ubuntu-decision.md @@ -353,4 +353,4 @@ When you install with a package manager, these libraries are installed for you. - [.NET CLI overview](../tools/index.md) - [How to enable Tab completion for the .NET CLI](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET](../tutorials/create-console-app.md) diff --git a/docs/core/install/linux-ubuntu-install.md b/docs/core/install/linux-ubuntu-install.md index 730cd4b80f2f8..6588817fb77bf 100644 --- a/docs/core/install/linux-ubuntu-install.md +++ b/docs/core/install/linux-ubuntu-install.md @@ -246,4 +246,4 @@ When you install with a package manager, these libraries are installed for you. - [.NET CLI overview](../tools/index.md) - [How to enable TAB completion for the .NET CLI.](../tools/enable-tab-autocomplete.md) -- [Tutorial: Create a console application with .NET SDK using Visual Studio Code.](../tutorials/with-visual-studio-code.md) +- [Tutorial: Create a console application with .NET.](../tutorials/create-console-app.md) diff --git a/docs/core/install/macos.md b/docs/core/install/macos.md index fa369d06c79fa..8927b3d6e9c3c 100644 --- a/docs/core/install/macos.md +++ b/docs/core/install/macos.md @@ -352,5 +352,5 @@ Set the following two environment variables in your shell profile: - [How to check if .NET is already installed](how-to-detect-installed-versions.md?pivots=os-macos). - [Working with macOS Catalina notarization](macos-notarization-issues.md). -- [Tutorial: Create a new app with Visual Studio Code](../tutorials/with-visual-studio-code.md). +- [Tutorial: Create a .NET console application](../tutorials/create-console-app.md). - [Tutorial: Containerize a .NET app](../docker/build-container.md). diff --git a/docs/core/install/windows.md b/docs/core/install/windows.md index 197bbbc97469b..20605de2f87dd 100644 --- a/docs/core/install/windows.md +++ b/docs/core/install/windows.md @@ -509,8 +509,7 @@ Install the Microsoft Visual C++ 2015-2019 Redistributable ([64-bit][vcc64] or [ - [.NET CLI overview](../tools/index.md) - [Upgrade to a new .NET version](upgrade.md). - [How to check if .NET is already installed](how-to-detect-installed-versions.md?pivots=os-windows). -- [Tutorial: Hello World tutorial](../tutorials/with-visual-studio.md). -- [Tutorial: Create a new app with Visual Studio Code](../tutorials/with-visual-studio-code.md). +- [Tutorial: Create a new console application](../tutorials/create-console-app.md). [esu]: /troubleshoot/windows-client/windows-7-eos-faq/windows-7-extended-security-updates-faq [vcc64]: https://aka.ms/vs/16/release/vc_redist.x64.exe diff --git a/docs/core/tutorials/create-class-library.md b/docs/core/tutorials/create-class-library.md new file mode 100644 index 0000000000000..03d3aa212f713 --- /dev/null +++ b/docs/core/tutorials/create-class-library.md @@ -0,0 +1,416 @@ +--- +title: Create a .NET class library +description: Learn how to create a .NET class library using Visual Studio, Visual Studio Code, or GitHub Codespaces. +ms.date: 02/12/2026 +ai-usage: ai-assisted +zone_pivot_groups: code-editor-set-one +dev_langs: + - "csharp" + - "vb" +--- +# Tutorial: Create a .NET class library + +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 10, it can be called by any application that targets .NET 10. This tutorial shows how to target .NET 10. + +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 + +::: zone pivot="visualstudio" + +- [Visual Studio](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=learn.microsoft.com&utm_campaign=inline+link) with the **.NET desktop development** workload installed. The .NET SDK is automatically installed when you select this workload. + + For more information, see [Install the .NET SDK with Visual Studio](../install/windows.md#install-with-visual-studio). + +::: zone-end + +::: zone pivot="vscode" + +[!INCLUDE [Prerequisites](../../../includes/prerequisites-basic-winget.md)] + +::: zone-end + +::: zone pivot="codespaces" + +- A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, you can create a free account at [GitHub.com](https://github.com). + +::: zone-end + +## Create a solution + +::: zone pivot="visualstudio" + +Start by creating a blank solution to hold the class library project. A Visual Studio solution serves as a container for one or more projects. Add related projects to the same solution. + +To create the blank solution: + +1. Start Visual Studio. + +1. On the start window, choose **Create a new project**. + +1. On the **Create a new project** page, enter **solution** in the search box. Choose the **Blank Solution** template, and then choose **Next**. + + :::image type="content" source="media/create-class-library/blank-solution.png" alt-text="Blank solution template in Visual Studio"::: + +1. On the **Configure your new project** page, enter **ClassLibraryProjects** in the **Solution name** box. Then choose **Create**. + +::: zone-end + +::: zone pivot="vscode" + +Start by creating a .NET class library project named "StringLibrary" and an associated solution. A solution serves as a container for one or more projects. You'll add additional, related projects to the same solution. + +1. Start Visual Studio Code. + +1. Go to the Explorer view and select **Create .NET Project**. Alternatively, you can bring up the Command Palette using Ctrl+Shift+P (Command+Shift+P on MacOS) and then type ".NET" and find and select the .NET: New Project command. + +1. Choose the project template **Class Library**. + +1. Then select the location where you would like the new project to be created: Create a folder named `ClassLibraryProjects` and select it. + +1. Name the project **StringLibrary**. + +1. Select **.sln** as the solution file format. + +1. Select **Show all template options**. + +1. Next select **.NET 10**. Then select **Create Project**. + +1. In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. You can trust the authors because this folder only has files generated by .NET and added or modified by you. + +::: zone-end + +::: zone pivot="codespaces" + +Start by creating a GitHub Codespace with the tutorial environment, then create a .NET class library project. + +1. Open a browser window and navigate to the [tutorial codespace](https://github.com/dotnet/tutorial-codespace) repository. + +1. Select the green **Code** button, and then the **Codespaces** tab. + +1. Select the `+` sign or the green **Create codespace on main** button to create a new Codespace using this environment. + + :::image type="content" source="media/create-console-app/create-codespace-on-main.png" alt-text="Create a new Codespace from the tutorial repository"::: + +1. When your codespace loads, open the terminal and navigate to the tutorials folder: + + ```bash + cd tutorials + ``` + +1. Create a new class library project: + + ```dotnetcli + dotnet new classlib -n StringLibrary + ``` + +::: zone-end + +## Create a class library project + +::: zone pivot="visualstudio" + +1. Add a new .NET class library project named **StringLibrary** to the solution. + + 1. Right-click on the solution in **Solution Explorer** and select **Add** > **New Project**. + + 1. On the **Add a new project** page, enter **library** in the search box. Choose **C#** or **Visual Basic** from the Language list, and then choose **All platforms** from the Platform list. Choose the **Class Library** template, and then choose **Next**. + + 1. On the **Configure your new project** page, enter **StringLibrary** in the **Project name** box, and then choose **Next**. + + 1. On the **Additional information** page, select **.NET 10**, and then choose **Create**. + +1. Check to make sure that the library targets the correct version of .NET. Right-click on the library project in **Solution Explorer**, and then select **Properties**. The **Target Framework** text box shows that the project targets .NET 10.0. + +1. If you're using Visual Basic, clear the text in the **Default namespace** text box. + + :::image type="content" source="./media/create-class-library/vb/library-project-properties.png" alt-text="Project properties for the class library"::: + + For each project, Visual Basic automatically creates a namespace that corresponds to the project name. In this tutorial, you define a top-level namespace by using the [`namespace`](../../visual-basic/language-reference/statements/namespace-statement.md) keyword in the code file. + +1. Replace the code in the code window for *Class1.cs* or *Class1.vb* with the following code, and save the file. If the language you want to use isn't shown, change the language selector at the top of the page. + + :::code language="csharp" source="./snippets/create-class-library/csharp/StringLibrary/Class1.cs"::: + :::code language="vb" source="./snippets/create-class-library/vb/StringLibrary/Class1.vb"::: + + The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The 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 class. The question mark (`?`) after `string` in the C# code indicates that the string may be null. + +1. On the menu bar, select **Build** > **Build Solution** or press Ctrl+Shift+B to verify that the project compiles without error. + +::: zone-end + +::: zone pivot="vscode" + +1. The project is created and *Class1.cs* opens. + +1. Replace the contents of *Class1.cs* with the following code: + + :::code language="csharp" source="./snippets/create-class-library/csharp/StringLibrary/Class1.cs"::: + + The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The 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 class. + +1. Save the file. + +1. Expand **Solution Explorer** at the bottom of the **Explorer** view. + +1. Right click the solution in **Solution Explorer** and select **Build**, or open the Command Palette and select **.NET: Build** to build the solution and verify that the project compiles without error. + + The terminal output looks like the following example: + + ```output + Determining projects to restore... + All projects are up-to-date for restore. + StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net10.0\StringLibrary.dll + Build succeeded. + 0 Warning(s) + 0 Error(s) + Time Elapsed 00:00:02.78 + ``` + +::: zone-end + +::: zone pivot="codespaces" + +1. Navigate to the StringLibrary folder: + + ```bash + cd StringLibrary + ``` + +1. Open *Class1.cs* and replace its contents with the following code: + + :::code language="csharp" source="./snippets/create-class-library/csharp/StringLibrary/Class1.cs"::: + + The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The 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 class. + +1. Save the file and build the project: + + ```dotnetcli + dotnet build + ``` + + The build should succeed with no errors. + +::: zone-end + +## Add a console app to the solution + +Add a console application that uses the class library. The app will prompt the user to enter a string and report whether the string begins with an uppercase character. + +::: zone pivot="visualstudio" + +1. Add a new .NET console application named **ShowCase** to the solution. + + 1. Right-click on the solution in **Solution Explorer** and select **Add** > **New Project**. + + 1. On the **Add a new project** page, enter **console** in the search box. Choose **C#** or **Visual Basic** from the Language list, and then choose **All platforms** from the Platform list. + + 1. Choose the **Console App** template, and then choose **Next**. + + 1. On the **Configure your new project** page, enter **ShowCase** in the **Project name** box. Then choose **Next**. + + 1. On the **Additional information** page, select **.NET 10** in the **Framework** box. Then choose **Create**. + +1. In the code window for the *Program.cs* or *Program.vb* file, replace all of the code with the following code. + + :::code language="csharp" source="./snippets/create-class-library/csharp/ShowCase/Program.cs"::: + :::code language="vb" source="./snippets/create-class-library/vb/ShowCase/Program.vb"::: + + 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. + + The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the Enter key without entering a string, the application ends, and the console window closes. + +::: zone-end + +::: zone pivot="vscode" + +1. Right-click the solution in **Solution Explorer** and select **New Project**, or in the Command Palette select **.NET: New Project**. + +1. Select **Console App**. + +1. Give it the name **ShowCase**, select the default directory and select **Create Project**. + +1. Open *ShowCase/Program.cs* and replace all of the code with the following code. + + :::code language="csharp" source="./snippets/create-class-library/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. + + The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the Enter key without entering a string, the application ends, and the console window closes. + +1. Save your changes. + +::: zone-end + +::: zone pivot="codespaces" + +1. Navigate back to the tutorials folder and create a new console app: + + ```bash + cd .. + dotnet new console -n ShowCase + ``` + +1. Open *ShowCase/Program.cs* and replace all of the code with the following code: + + :::code language="csharp" source="./snippets/create-class-library/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. + + The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the Enter key without entering a string, the application ends, and the console window closes. + +1. Save your changes. + +::: zone-end + +## Add a project reference + +Initially, the new console app project doesn't have access to the class library. To allow it to call methods in the class library, create a project reference to the class library project. + +::: zone pivot="visualstudio" + +1. In **Solution Explorer**, right-click the `ShowCase` project's **Dependencies** node, and select **Add Project Reference**. + + :::image type="content" source="media/create-class-library/add-reference-context-menu.png" alt-text="Add reference context menu in Visual Studio"::: + +1. In the **Reference Manager** dialog, select the **StringLibrary** project, and select **OK**. + + :::image type="content" source="media/create-class-library/manage-project-references.png" alt-text="Reference Manager dialog with StringLibrary selected"::: + +::: zone-end + +::: zone pivot="vscode" + +1. In **Solution Explorer** right click on the **ShowCase** project and select **Add Project Reference**. + +1. Select StringLibrary. + +> [!TIP] +> Alternatively, add the following to *ShowCase.csproj*: +> +> ```xml +> +> +> +> ``` + +::: zone-end + +::: zone pivot="codespaces" + +Add a reference to the StringLibrary project from the ShowCase project: + +```bash +cd ShowCase +dotnet add reference ../StringLibrary/StringLibrary.csproj +``` + +::: zone-end + +## Run the app + +::: zone pivot="visualstudio" + +1. In **Solution Explorer**, right-click the **ShowCase** project and select **Set as StartUp Project** in the context menu. + + :::image type="content" source="media/create-class-library/set-startup-project-context-menu.png" alt-text="Visual Studio project context menu to set startup project"::: + +1. Press Ctrl+F5 to compile and run the program without debugging. + +1. Try out the program by entering strings and pressing Enter, then press Enter to exit. + + :::image type="content" source="media/create-class-library/run-showcase.png" alt-text="Console window with ShowCase running"::: + +::: zone-end + +::: zone pivot="vscode" + +1. Use the top menu bar to select **Run** > **Run without debugging**. + +1. Select **C#**. + +1. Select **C#: ShowCase**. + + If you get an error that says no C# program is loaded, close the folder that you have open, and open the `ShowCase` folder. Then try running the app again. + +1. Try out the program by entering strings and pressing Enter, then press Enter to exit. + + The terminal output looks like the following example: + + ```output + Press only to exit; otherwise, enter a string and press : + + A string that starts with an uppercase letter + Input: A string that starts with an uppercase letter + Begins with uppercase? : Yes + + a string that starts with a lowercase letter + Input: a string that starts with a lowercase letter + Begins with uppercase? : No + ``` + +::: zone-end + +::: zone pivot="codespaces" + +1. Run the ShowCase app: + + ```dotnetcli + dotnet run + ``` + +1. Try out the program by entering strings and pressing Enter, then press Enter to exit. + + The terminal output looks like the following example: + + ```output + Press only to exit; otherwise, enter a string and press : + + A string that starts with an uppercase letter + Input: A string that starts with an uppercase letter + Begins with uppercase? : Yes + + a string that starts with a lowercase letter + Input: a string that starts with a lowercase letter + Begins with uppercase? : No + ``` + +::: zone-end + +## Additional resources + +- [Develop libraries with the .NET CLI](libraries.md) +- [.NET Standard versions and the platforms they support](../../standard/net-standard.md). + +::: zone pivot="codespaces" + +## Cleanup resources + +GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace. Then select "Delete". + +::: zone-end + +## Next steps + +In this tutorial, you created a class library. In the next tutorial, you learn how to unit test the class library. + +> [!div class="nextstepaction"] +> [Unit test a .NET class library](test-class-library.md) + +Or, you can skip automated unit testing and learn how to share the library by creating a NuGet package: + +> [!div class="nextstepaction"] +> [Create and publish a package using Visual Studio](/nuget/quickstart/create-and-publish-a-package-using-visual-studio) + +Or, learn how to publish a console app. If you publish the console app from the solution you created in this tutorial, the class library goes with it as a *.dll* file. + +> [!div class="nextstepaction"] +> [Publish a .NET console application](publish-console-app.md) diff --git a/docs/core/tutorials/with-visual-studio-code.md b/docs/core/tutorials/create-console-app.md similarity index 53% rename from docs/core/tutorials/with-visual-studio-code.md rename to docs/core/tutorials/create-console-app.md index 45bee81113cf0..d492d49dc60de 100644 --- a/docs/core/tutorials/with-visual-studio-code.md +++ b/docs/core/tutorials/create-console-app.md @@ -1,10 +1,28 @@ --- -title: Create a .NET console application using Visual Studio Code -description: Learn how to create a .NET console application using Visual Studio Code. -ms.date: 01/26/2026 +title: Create a .NET console application +description: Learn how to create a .NET console application using Visual Studio, Visual Studio Code, or GitHub Codespaces. +ms.date: 02/12/2026 +ai-usage: ai-assisted zone_pivot_groups: code-editor-set-one +dev_langs: + - "csharp" + - "vb" --- -# Tutorial: Create a .NET console application using Visual Studio Code +# Tutorial: Create a .NET console application + +::: zone pivot="visualstudio" + +This tutorial shows how to create and run a .NET console application in Visual Studio. + +In this tutorial, you: + +> [!div class="checklist"] +> +> * Create a Visual Studio solution and console app project. +> * Create a "HelloWorld" .NET console application. +> * Enhance the app to prompt the user for their name and display it in the console window. + +::: zone-end ::: zone pivot="vscode" @@ -29,13 +47,21 @@ In this tutorial, you: > [!div class="checklist"] > > * Launch a GitHub Codespace with a C# development environment. -> * Create a "HelloWorld" .NET single-file app. +> * Create a "HelloWorld" .NET file-based app. > * Enhance the app to prompt the user for their name and display it in the console window. ::: zone-end ## Prerequisites +::: zone pivot="visualstudio" + +- [Visual Studio](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=learn.microsoft.com&utm_campaign=inline+link) with the **.NET desktop development** workload installed. The .NET SDK is automatically installed when you select this workload. + + For more information, see [Install the .NET SDK with Visual Studio](../install/windows.md#install-with-visual-studio). + +::: zone-end + ::: zone pivot="vscode" [!INCLUDE [Prerequisites](../../../includes/prerequisites-basic-winget.md)] @@ -50,6 +76,56 @@ In this tutorial, you: ## Create the app +::: zone pivot="visualstudio" + +Create a .NET console app project named "HelloWorld". + +1. Start Visual Studio. + +1. On the start page, choose **Create a new project**. + + :::image type="content" source="./media/create-console-app/start-window.png" alt-text="Create a new project button selected on the Visual Studio start page"::: + +1. On the **Create a new project** page, enter **console** in the search box. Next, choose **C#** or **Visual Basic** from the language list, and then choose **All platforms** from the platform list. Choose the **Console App** template, and then choose **Next**. + + :::image type="content" source="./media/create-console-app/create-new-project.png" alt-text="Create a new project window with filters selected"::: + + > [!TIP] + > If you don't see the .NET templates, you're probably missing the required workload. Under the **Not finding what you're looking for?** message, choose the **Install more tools and features** link. The Visual Studio Installer opens. Make sure you have the **.NET desktop development** workload installed. + +1. In the **Configure your new project** dialog, enter **HelloWorld** in the **Project name** box. Then choose **Next**. + + :::image type="content" source="./media/create-console-app/configure-new-project.png" alt-text="Configure your new project window with Project name, location, and solution name fields"::: + +1. In the **Additional information** dialog: + - Select **.NET 10.0 (Long Term Support)**. + - Select **Create**. + + :::image type="content" source="./media/create-console-app/additional-information.png" alt-text="Enter additional information for the console app."::: + + The template creates a simple application that displays "Hello, World!" in the console window. The code is in the *Program.cs* or *Program.vb* file: + + ```csharp + // See https://aka.ms/new-console-template for more information + Console.WriteLine("Hello, World!"); + ``` + + ```vb + Imports System + + Module Program + Sub Main(args As String()) + Console.WriteLine("Hello World!") + End Sub + End Module + ``` + + If the language you want to use is not shown, change the language selector at the top of the page. + + The C# template uses top-level statements to call the method to display a message in the console window. The Visual Basic template defines a `Module Program` with a `Sub Main` method that calls the same method. + +::: zone-end + ::: zone pivot="vscode" Create a .NET console app project named "HelloWorld". @@ -58,7 +134,7 @@ Create a .NET console app project named "HelloWorld". 1. Go to the Explorer view and select **Create .NET Project**. Alternatively, you can bring up the Command Palette using Ctrl+Shift+P (Command+Shift+P on MacOS) and then type ".NET" and find and select the .NET: New Project command. - :::image type="content" source="media/with-visual-studio-code/create-dotnet-project.png" alt-text="The .NET: New Project command in the Command Palette"::: + :::image type="content" source="media/create-console-app/create-dotnet-project.png" alt-text="The .NET: New Project command in the Command Palette"::: 1. After selecting the command, you need to choose the project template. Choose **Console App**. @@ -93,7 +169,7 @@ Start a GitHub Codespace with the tutorial environment. 1. Select the `+` sign or the green **Create codespace on main** button to create a new Codespace using this environment. - :::image type="content" source="media/with-visual-studio-code/create-codespace-on-main.png" alt-text="Create a new Codespace from the tutorial repository"::: + :::image type="content" source="media/create-console-app/create-codespace-on-main.png" alt-text="Create a new Codespace from the tutorial repository"::: ### Create a .NET file-based app @@ -101,16 +177,26 @@ In Codespaces, you'll create a [file-based app](../sdk/file-based-apps.md). File 1. When your codespace loads, right-click on the *tutorials* folder and select **New File...**. Enter the name *HelloWorld.cs* and then press Enter. - :::image type="content" source="media/with-visual-studio-code/codespaces-create-new-file.png" alt-text="Create a new file named HelloWorld.cs in the tutorials folder"::: + :::image type="content" source="media/create-console-app/codespaces-create-new-file.png" alt-text="Create a new file named HelloWorld.cs in the tutorials folder"::: 1. *HelloWorld.cs* opens in the editor. Type or copy the following code into the file: - :::code language="csharp" source="./snippets/with-visual-studio-code/csharp/HelloWorld.cs" id="HelloWorld"::: + :::code language="csharp" source="../snippets/get-started/csharp/hello-world.cs" id="HelloWorld"::: ::: zone-end ## Run the app +::: zone pivot="visualstudio" + +1. Press Ctrl+F5 to run the program without debugging. + + A console window opens with the text "Hello, World!" printed on the screen. (Or "Hello World!" without a comma in the Visual Basic project template.) + +1. Press any key to close the console window. + +::: zone-end + ::: zone pivot="vscode" To run your app, select **Run** > **Run without Debugging** in the upper menu, or use the keyboard shortcut (Ctrl+F5). @@ -138,13 +224,36 @@ The program displays "Hello, World!" and ends. Enhance the application to prompt the user for their name and display it along with the date and time. +::: zone pivot="visualstudio" + +1. In *Program.cs* or *Program.vb*, replace the contents with the following code: + + :::code language="csharp" source="./snippets/create-console-app/csharp/Program.cs" id="MainMethod"::: + :::code language="vb" source="./snippets/create-console-app/vb/Program.vb" id="MainMethod"::: + + This code displays a prompt in the console window and waits until the user enters a string followed by the Enter key. It stores this string in a variable named `name`. It also retrieves the value of the property, which contains the current local time, and assigns it to a variable named `currentDate`. And it displays these values in the console window. Finally, it displays a prompt in the console window and calls the method to wait for user input. + + is a platform-independent and language-independent way to represent a line break. Alternatives are `\n` in C# and `vbCrLf` in Visual Basic. + + The dollar sign (`$`) in front of a string lets you put expressions such as variable names in curly braces in the string. The expression value is inserted into the string in place of the expression. This syntax is referred to as [interpolated strings](../../csharp/language-reference/tokens/interpolated.md). + +1. Press Ctrl+F5 to run the program without debugging. + +1. Respond to the prompt by entering a name and pressing the Enter key. + + :::image type="content" source="./media/create-console-app/hello-world-update.png" alt-text="Console window with modified program output"::: + +1. Press any key to close the console window. + +::: zone-end + ::: zone pivot="vscode" 1. Open *Program.cs*. 1. Replace the contents of the class with the following code: - :::code language="csharp" source="./snippets/with-visual-studio/csharp/Program-Read.cs" id="MainMethod"::: + :::code language="csharp" source="./snippets/create-console-app/csharp/Program.cs" id="MainMethod"::: This code displays a prompt in the console window and waits until the user enters a string followed by the Enter key. It stores this string in a variable named `name`. It also retrieves the value of the property, which contains the current local time, and assigns it to a variable named `currentDate`. And it displays these values in the console window. Finally, it displays a prompt in the console window and calls the method to wait for user input. @@ -161,7 +270,7 @@ Enhance the application to prompt the user for their name and display it along w 1. Respond to the prompt by entering a name and pressing the Enter key. - :::image type="content" source="media/with-visual-studio-code/run-program-class.png" alt-text="Terminal window with modified program output"::: + :::image type="content" source="media/create-console-app/run-program-class.png" alt-text="Terminal window with modified program output"::: Press Enter to exit the program. @@ -171,7 +280,7 @@ Enhance the application to prompt the user for their name and display it along w 1. Update *HelloWorld.cs* with the following code: - :::code language="csharp" source="./snippets/with-visual-studio-code/csharp/HelloWorld.cs" id="MainMethod"::: + :::code language="csharp" source="./snippets/create-console-app/csharp/Program.cs" id="MainMethod"::: This code displays a prompt in the console window and waits until the user enters a string followed by the Enter key. It stores this string in a variable named `name`. It also retrieves the value of the property, which contains the current local time, and assigns it to a variable named `currentDate`. And it displays these values in the console window. Finally, it displays a prompt in the console window and calls the method to wait for user input. @@ -201,6 +310,12 @@ Enhance the application to prompt the user for their name and display it along w ## Additional resources +::: zone pivot="visualstudio" + +- [Standard-term support (STS) releases and long-term support (LTS) releases](../releases-and-support.md#release-tracks). + +::: zone-end + ::: zone pivot="vscode" * [Setting up Visual Studio Code](https://code.visualstudio.com/docs/setup/setup-overview) @@ -214,7 +329,7 @@ Enhance the application to prompt the user for their name and display it along w ## Cleanup resources -GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace. Then select "delete". +GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace. Then select "Delete". ::: zone-end @@ -223,4 +338,4 @@ GitHub automatically deletes your Codespace after 30 days of inactivity. If you In this tutorial, you created a .NET console application. In the next tutorial, you debug the app. > [!div class="nextstepaction"] -> [Debug a .NET console application using Visual Studio Code](debugging-with-visual-studio-code.md) +> [Debug a .NET console application](debug-console-app.md) diff --git a/docs/core/tutorials/debug-console-app.md b/docs/core/tutorials/debug-console-app.md new file mode 100644 index 0000000000000..284723aafba59 --- /dev/null +++ b/docs/core/tutorials/debug-console-app.md @@ -0,0 +1,437 @@ +--- +title: Debug a .NET console application +description: Learn how to debug a .NET console app using Visual Studio, Visual Studio Code, or GitHub Codespaces. +ms.date: 02/12/2026 +ai-usage: ai-assisted +zone_pivot_groups: code-editor-set-one +dev_langs: + - "csharp" + - "vb" +--- +# Tutorial: Debug a .NET console application + +::: zone pivot="visualstudio" + +This tutorial introduces the debugging tools available in Visual Studio. + +> [!IMPORTANT] +> All of the keyboard shortcuts are based on the defaults from Visual Studio. Your keyboard shortcuts may vary, for more information see [Keyboard shortcuts in Visual Studio](/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio). + +::: zone-end + +::: zone pivot="vscode" + +This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps. + +::: zone-end + +::: zone pivot="codespaces" + +This tutorial introduces the debugging tools available in GitHub Codespaces for working with .NET apps. + +::: zone-end + +## Prerequisites + +This tutorial works with the console app that you create in [Create a .NET console application](create-console-app.md). + +::: zone pivot="visualstudio" + +## Use Debug build configuration + +*Debug* and *Release* are Visual Studio'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. + +By default, Visual Studio uses the Debug build configuration, so you don't need to change it before debugging. + +1. Start Visual Studio. + +1. Open the project that you created in [Create a .NET console application](create-console-app.md). + + The current build configuration is shown on the toolbar. The following toolbar image shows that Visual Studio is configured to compile the Debug version of the app: + + :::image type="content" source="./media/debug-console-app/use-debug-configuration.png" alt-text="Visual Studio toolbar with debug highlighted"::: + +::: zone-end + +## Set a breakpoint + +A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is run. + +::: zone pivot="visualstudio" + +1. Set a *breakpoint* on the line that displays the name, date, and time, by clicking in the left margin of the code window on that line. The left margin is to the left of the line numbers. Other ways to set a breakpoint are by placing the cursor in the line of code and then pressing F9 or choosing **Debug** > **Toggle Breakpoint** from the menu bar. + + As the following image shows, Visual Studio indicates the line on which the breakpoint is set by highlighting it and displaying a red dot in the left margin. + + :::image type="content" source="./media/debug-console-app/set-breakpoint.png" alt-text="Visual Studio Program window with breakpoint set"::: + +1. Press F5 to run the program in Debug mode. Another way to start debugging is by choosing **Debug** > **Start Debugging** from the menu. + +1. Enter a string in the console window when the program prompts for a name, and then press Enter. + +1. Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method executes. The **Locals** window displays the values of variables that are defined in the currently executing method. + + :::image type="content" source="./media/debug-console-app/breakpoint-hit.png" alt-text="Screenshot of a breakpoint in Visual Studio"::: + +::: zone-end + +::: zone pivot="vscode" + +1. Start Visual Studio Code. + +1. Open the folder of the project that you created in [Create a .NET console application](create-console-app.md). + +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 F9 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/debug-console-app/breakpoint-set.png" alt-text="Breakpoint set"::: + +::: zone-end + +::: zone pivot="codespaces" + +1. Open your GitHub Codespace that you created in [Create a .NET console application](create-console-app.md). + +1. Open the *HelloWorld.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. You can also set a breakpoint are by pressing F9 while the line of code is selected. + + :::image type="content" source="media/debug-console-app/codespaces-breakpoint-set.png" alt-text="Breakpoint set"::: + +::: zone-end + +## Start debugging + +::: zone pivot="visualstudio" + +Program execution stops when it reaches the breakpoint, as described in the previous section. The **Locals** window displays the values of variables that are defined in the currently executing method. + +::: zone-end + +::: zone pivot="vscode" + +*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. + +By default, Visual Studio Code launch settings use the Debug build configuration, so you don't need to change it before debugging. + +1. Open the Debug view by selecting the Debugging icon on the left side menu. + + :::image type="content" source="media/debug-console-app/select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code"::: + +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 F5 or choosing **Run** > **Start Debugging** from the menu. + + :::image type="content" source="media/debug-console-app/start-debugging.png" alt-text="Start debugging"::: + +1. If asked to **Select Launch Configuration**, select **C#: Debug Active File**. + +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/debug-console-app/select-debug-console.png" alt-text="Select the Debug Console tab"::: + +1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press Enter. + + 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/debug-console-app/breakpoint-hit.png" alt-text="Breakpoint hit, showing Locals"::: + +::: zone-end + +::: zone pivot="codespaces" + +By default, GitHub Codespaces uses the Debug build configuration, so you don't need to change it before debugging. + +1. Open the Debug view by selecting the Debugging icon on the left side menu. + + :::image type="content" source="media/debug-console-app/codespaces-select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code"::: + +1. Select **Run and Debug**. If asked, select **C#** as the debugger and then select **C#: Debug Active File** as the Launch Configuration. + +1. Select the **Debug Console** tab to see the "What is your name?" prompt that the program displays before waiting for a response. + +1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press Enter. + + 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/debug-console-app/codespaces-breakpoint-hit.png" alt-text="Breakpoint hit, showing Locals"::: + +::: zone-end + +::: zone pivot="visualstudio" + +## Use the Immediate window + +The **Immediate** window lets you interact with the application you're debugging. You can interactively change the value of variables to see how it affects your program. + +1. If the **Immediate** window is not visible, display it by choosing **Debug** > **Windows** > **Immediate**. + +1. Enter `name = "Gracie"` in the **Immediate** window and press the Enter key. + +1. Enter `currentDate = DateTime.Parse("2026-02-05T20:25:00Z").ToUniversalTime()` in the **Immediate** window and press the Enter key. + + The **Immediate** window displays the value of the string variable and the properties of the value. In addition, the values of the variables are updated in the **Locals** window. + + :::image type="content" source="./media/debug-console-app/locals-immediate-window.png" alt-text="Locals and Immediate Windows in Visual Studio"::: + +1. Press F5 to continue program execution. Another way to continue is by choosing **Debug** > **Continue** from the menu. + + The values displayed in the console window correspond to the changes you made in the **Immediate** window. + +1. Press any key to exit the application and stop debugging. + +::: zone-end + +::: zone pivot="vscode,codespaces" + +## Use the Debug Console + +The **Debug Console** window lets you interact with the application you're debugging. You can change the value of variables to see how it affects your program. + +1. Select the **Debug Console** tab. + +1. Enter `name = "Gracie"` at the prompt at the bottom of the **Debug Console** window and press Enter. + + :::image type="content" source="media/debug-console-app/change-variable-values.png" alt-text="Change variable values"::: + +1. Enter `currentDate = DateTime.Parse("2026-01-28T20:54:00Z").ToUniversalTime()` at the bottom of the **Debug Console** window and press Enter. + + The **Variables** window displays the new values of the `name` and `currentDate` variables. + +1. Continue program execution by selecting the **Continue** button in the toolbar. Another way to continue is by pressing F5. + + :::image type="content" source="media/debug-console-app/continue-debugging.png" alt-text="Continue debugging"::: + + The values displayed in the console window correspond to the changes you made in the **Debug Console**. + + :::image type="content" source="media/debug-console-app/codespaces-changed-variable-values.png" alt-text="Terminal showing the entered values"::: + +1. Press Enter to exit the application and stop debugging. + +::: zone-end + +## Set a conditional breakpoint + +The program displays the string that the user enters. What happens if the user doesn't enter anything? You can test this with a useful debugging feature called a *conditional breakpoint*. + +::: zone pivot="visualstudio" + +1. Right-click on the red dot that represents the breakpoint. In the context menu, select **Conditions** to open the **Breakpoint Settings** dialog. Select the box for **Conditions** if it's not already selected. + + :::image type="content" source="./media/debug-console-app/breakpoint-settings.png" alt-text="Editor showing breakpoint settings panel - C#"::: + +1. For the **Conditional Expression**, enter the following code in the text field. + + ```csharp + string.IsNullOrEmpty(name) + ``` + + ```vb + String.IsNullOrEmpty(name) + ``` + + 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. + +1. Select **Close** to close the dialog. + +1. Start the program with debugging by pressing F5. + +1. In the console window, press the Enter key when prompted to enter your name. + +1. Because the condition you specified (`name` is either `null` or ) has been satisfied, program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method executes. + +1. Select the **Locals** window, which shows the values of variables that are local to the currently executing method. In this case, `Main` is the currently executing method. Observe that the value of the `name` variable is `""`, or . + +1. Confirm the value is an empty string by entering the following statement in the **Immediate** window and pressing Enter. The result is `true`. + + ```csharp + ? name == String.Empty + ``` + + ```vb + ? String.IsNullOrEmpty(name) + ``` + + The question mark directs the immediate window to [evaluate an expression](/visualstudio/ide/reference/immediate-window#enter-commands). + + :::image type="content" source="./media/debug-console-app/immediate-window-output.png" alt-text="Immediate Window returning a value of true after the statement is executed - C#"::: + +1. Press F5 to continue program execution. + +1. Press any key to close the console window 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 F9 or choosing **Debug > Toggle Breakpoint** while the line of code is selected. + +::: zone-end + +::: zone pivot="vscode,codespaces" + +1. Right-click (Ctrl-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/debug-console-app/breakpoint-context-menu.png" alt-text="Breakpoint context menu"::: + +1. Select `Expression` in the drop-down, enter the following conditional expression, and press Enter. + + ```csharp + String.IsNullOrEmpty(name) + ``` + + :::image type="content" source="media/debug-console-app/conditional-expression.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 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 F5. + +1. In the **Debug Console** tab, press Enter when prompted to enter your name. + + Because the condition you specified (`name` is either `null` or ) 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 . + +1. Confirm the value is an empty string by entering the following statement at the **Debug Console** prompt and pressing Enter. The result is `true`. + + ```csharp + name == String.Empty + ``` + +1. Select the **Continue** button on the toolbar to continue program execution. + +1. Press Enter 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 F9 or choosing **Run > Toggle Breakpoint** from the menu while the line of code is selected. + +1. If you get a warning that the breakpoint condition will be lost, select **Remove Breakpoint**. + +::: zone-end + +## Step through a program + +::: zone pivot="visualstudio" + +Visual Studio 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. + +1. Set a breakpoint on the line of code that displays the "What is your name?" prompt. + +1. Choose **Debug** > **Step Into**. Another way to debug one statement at a time is by pressing F11. + + Visual Studio highlights and displays an arrow beside the next line of execution. + + :::image type="content" source="./media/debug-console-app/step-into-method.png" alt-text="Visual Studio step into method - C#"::: + + At this point, the **Locals** window shows that the `args` array is empty, and `name` and `currentDate` have default values. In addition, Visual Studio has opened a blank console window. + +1. Press F11. Visual Studio highlights the statement that includes the `name` variable assignment. The **Locals** window shows that `name` is `null`, and the console window displays the string "What is your name?". + +1. Respond to the prompt by entering a string in the console window and pressing Enter. The console is unresponsive, and the string you entered isn't displayed in the console window, but the method will nevertheless capture your input. + +1. Press F11. Visual Studio highlights the statement that includes the `currentDate` variable assignment. The **Locals** window shows the value returned by the call to the method. The console window also displays the string you entered at the prompt. + +1. Press F11. The **Locals** window shows the value of the `currentDate` variable after the assignment from the property. The console window is unchanged. + +1. Press F11. Visual Studio calls the method. The console window displays the formatted string. + +1. Choose **Debug** > **Step Out**. Another way to stop step-by-step execution is by pressing Shift+F11. + + The console window displays a message and waits for you to press a key. + +1. Press any key to close the console window and stop debugging. + +::: zone-end + +::: zone pivot="vscode,codespaces" + +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. + +1. Set a breakpoint on the line of code that displays the "What is your name?" prompt. + +1. Press F5 to start debugging. + + Visual Studio Code highlights the breakpoint line. + + At this point, the **Variables** window shows that the `args` array is empty, and `name` and `currentDate` have default values. + +1. Select **Step Into** from the Debug toolbar or press F11. + + :::image type="content" source="media/debug-console-app/step-into.png" alt-text="Step-Into button"::: + + Visual Studio Code highlights the next line. + +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. + +1. Select **Step Into** or press F11. + + Visual Studio Code highlights the `name` variable assignment. The **Variables** window shows that `name` is still `null`. + +1. Respond to the prompt by entering a string in the Terminal tab and pressing Enter. + + The **Debug Console** tab might not display the string you enter while you're entering it, but the method will capture your input. + +1. Select **Step Into** or press F11. + + Visual Studio Code highlights the `currentDate` variable assignment. The **Variables** window shows the value returned by the call to the method. The **Terminal** tab displays the string you entered at the prompt. + +1. Select **Step Into** or press F11. + + The **Variables** window shows the value of the `currentDate` variable after the assignment from the property. + +1. Select **Step Into** or press F11. + + Visual Studio Code calls the method. The console window displays the formatted string. + +1. Select **Step Out** or press Shift+F11. + + :::image type="content" source="media/debug-console-app/step-out.png" alt-text="Step-Out button"::: + + The terminal displays "Press any key to exit..." + +1. Press any key to exit the program. + +::: zone-end + +## Use Release build configuration + +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 sometimes negatively affect the behavior of an application. For example, compiler optimizations that are designed to improve performance can create race conditions in multithreaded applications. + +::: zone pivot="visualstudio" + +To build and test the Release version of your console application, change the build configuration on the toolbar from **Debug** to **Release**. + +:::image type="content" source="./media/debug-console-app/use-release-configuration.png" alt-text="default Visual Studio toolbar with release highlighted"::: + +When you press F5 or choose **Build Solution** from the **Build** menu, Visual Studio compiles the Release version of the application. You can test it as you did the Debug version. + +::: zone-end + +::: zone pivot="vscode" + +To build and test the Release version of your console application, open the **Terminal** and run the following command: + +```dotnetcli +dotnet run --configuration Release +``` + +::: zone-end + +::: zone pivot="codespaces" + +To build and test the Release version of your console application, run the following command in the terminal: + +```dotnetcli +dotnet run --configuration Release HelloWorld.cs +``` + +::: zone-end + +## Next steps + +In this tutorial, you used debugging tools. In the next tutorial, you publish a deployable version of the app. + +> [!div class="nextstepaction"] +> [Publish a .NET console application](publish-console-app.md) diff --git a/docs/core/tutorials/debugging-with-visual-studio-code.md b/docs/core/tutorials/debugging-with-visual-studio-code.md deleted file mode 100644 index 7d9488f747f45..0000000000000 --- a/docs/core/tutorials/debugging-with-visual-studio-code.md +++ /dev/null @@ -1,250 +0,0 @@ ---- -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: 01/27/2026 -zone_pivot_groups: code-editor-set-one ---- -# Tutorial: Debug a .NET console application using Visual Studio Code - -::: zone pivot="vscode" - -This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps. - -::: zone-end - -::: zone pivot="codespaces" - -This tutorial introduces the debugging tools available in GitHub Codespaces for working with .NET apps. - -::: zone-end - -## Prerequisites - -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). - -## Set a breakpoint - -A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is run. - -::: zone pivot="vscode" - -1. Start Visual Studio Code. - -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). - -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 F9 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"::: - -::: zone-end - -::: zone pivot="codespaces" - -1. Open your GitHub Codespace that you created in [Create a .NET console application using Visual Studio Code](with-visual-studio-code.md). - -1. Open the *HelloWorld.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. You can also set a breakpoint are by pressing F9 while the line of code is selected. - - :::image type="content" source="media/debugging-with-visual-studio-code/codespaces-breakpoint-set.png" alt-text="Breakpoint set"::: - -::: zone-end - -## Start debugging - -*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. - -::: zone pivot="vscode" - -By default, Visual Studio Code launch settings use the Debug build configuration, so you don't need to change it before debugging. - -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"::: - -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 F5 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. If asked to **Select Launch Configuration**, select **C#: Debug Active File**. - -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-debug-console.png" alt-text="Select the Debug Console tab"::: - -1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press Enter. - - 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"::: - -::: zone-end - -::: zone pivot="codespaces" - -By default, GitHub Codespaces uses the Debug build configuration, so you don't need to change it before debugging. - -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/codespaces-select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code"::: - -1. Select **Run and Debug**. If asked, select **C#** as the debugger and then select **C#: Debug Active File** as the Launch Configuration. - -1. Select the **Debug Console** tab to see the "What is your name?" prompt that the program displays before waiting for a response. - -1. Enter a string in the **Debug Console** window in response to the prompt for a name, and then press Enter. - - 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/codespaces-breakpoint-hit.png" alt-text="Breakpoint hit, showing Locals"::: - -::: zone-end - -## Use the Debug Console - -The **Debug Console** window lets you interact with the application you're debugging. You can change the value of variables to see how it affects your program. - -1. Select the **Debug Console** tab. - -1. Enter `name = "Gracie"` at the prompt at the bottom of the **Debug Console** window and press Enter. - - :::image type="content" source="media/debugging-with-visual-studio-code/change-variable-values.png" alt-text="Change variable values"::: - -1. Enter `currentDate = DateTime.Parse("2026-01-28T20:54:00Z").ToUniversalTime()` at the bottom of the **Debug Console** window and press Enter. - - The **Variables** window displays the new values of the `name` and `currentDate` variables. - -1. Continue program execution by selecting the **Continue** button in the toolbar. Another way to continue is by pressing F5. - - :::image type="content" source="media/debugging-with-visual-studio-code/continue-debugging.png" alt-text="Continue debugging"::: - - 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/codespaces-changed-variable-values.png" alt-text="Terminal showing the entered values"::: - -1. Press Enter to exit the application and stop debugging. - -## Set a conditional breakpoint - -The program displays the string that the user enters. What happens if the user doesn't enter anything? You can test this with a useful debugging feature called a *conditional breakpoint*. - -1. Right-click (Ctrl-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"::: - -1. Select `Expression` in the drop-down, enter the following conditional expression, and press Enter. - - ```csharp - String.IsNullOrEmpty(name) - ``` - - :::image type="content" source="media/debugging-with-visual-studio-code/conditional-expression.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 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 F5. - -1. In the **Debug Console** tab, press Enter when prompted to enter your name. - - Because the condition you specified (`name` is either `null` or ) 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 . - -1. Confirm the value is an empty string by entering the following statement at the **Debug Console** prompt and pressing Enter. The result is `true`. - - ```csharp - name == String.Empty - ``` - -1. Select the **Continue** button on the toolbar to continue program execution. - -1. Press Enter 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 F9 or choosing **Run > Toggle Breakpoint** from the menu while the line of code is selected. - -1. If you get a warning that the breakpoint condition will be lost, select **Remove Breakpoint**. - -## Step through a program - -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. - -1. Set a breakpoint on the line of code that displays the "What is your name?" prompt. - -1. Press F5 to start debugging. - - Visual Studio Code highlights the breakpoint line. - - At this point, the **Variables** window shows that the `args` array is empty, and `name` and `currentDate` have default values. - -1. Select **Step Into** from the Debug toolbar or press F11. - - :::image type="content" source="media/debugging-with-visual-studio-code/step-into.png" alt-text="Step-Into button"::: - - Visual Studio Code highlights the next line. - -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. - -1. Select **Step Into** or press F11. - - Visual Studio Code highlights the `name` variable assignment. The **Variables** window shows that `name` is still `null`. - -1. Respond to the prompt by entering a string in the Terminal tab and pressing Enter. - - The **Debug Console** tab might not display the string you enter while you're entering it, but the method will capture your input. - -1. Select **Step Into** or press F11. - - Visual Studio Code highlights the `currentDate` variable assignment. The **Variables** window shows the value returned by the call to the method. The **Terminal** tab displays the string you entered at the prompt. - -1. Select **Step Into** or press F11. - - The **Variables** window shows the value of the `currentDate` variable after the assignment from the property. - -1. Select **Step Into** or press F11. - - Visual Studio Code calls the method. The console window displays the formatted string. - -1. Select **Step Out** or press Shift+F11. - - :::image type="content" source="media/debugging-with-visual-studio-code/step-out.png" alt-text="Step-Out button"::: - - The terminal displays "Press any key to exit..." - -1. Press any key to exit the program. - -## Use Release build configuration - -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. - -::: zone pivot="vscode" - -To build and test the Release version of your console application, open the **Terminal** and run the following command: - -```dotnetcli -dotnet run --configuration Release -``` - -::: zone-end - -::: zone pivot="codespaces" - -To build and test the Release version of your console application, run the following command in the terminal: - -```dotnetcli -dotnet run --configuration Release HelloWorld.cs -``` - -::: zone-end - -## Next steps - -In this tutorial, you used Visual Studio Code debugging tools. In the next tutorial, you publish a deployable version of the app. - -> [!div class="nextstepaction"] -> [Publish a .NET console application using Visual Studio Code](publishing-with-visual-studio-code.md) diff --git a/docs/core/tutorials/debugging-with-visual-studio.md b/docs/core/tutorials/debugging-with-visual-studio.md deleted file mode 100644 index 1fc5f62b6b91c..0000000000000 --- a/docs/core/tutorials/debugging-with-visual-studio.md +++ /dev/null @@ -1,173 +0,0 @@ ---- -title: Debug a .NET console application using Visual Studio -description: Learn how to debug a .NET console app using Visual Studio. -ms.date: 01/14/2026 -ai-usage: ai-assisted -dev_langs: - - "csharp" - - "vb" -ms.custom: "vs-dotnet" ---- -# Tutorial: Debug a .NET console application using Visual Studio - -This tutorial introduces the debugging tools available in Visual Studio. - -> [!IMPORTANT] -> All of the keyboard shortcuts are based on the defaults from Visual Studio. Your keyboard shortcuts may vary, for more information see [Keyboard shortcuts in Visual Studio](/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio). - -## Prerequisites - -This tutorial works with the console app that you create in [Create a .NET console application using Visual Studio](with-visual-studio.md). - -## Use Debug build configuration - -*Debug* and *Release* are Visual Studio'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. - -By default, Visual Studio uses the Debug build configuration, so you don't need to change it before debugging. - -1. Start Visual Studio. - -1. Open the project that you created in [Create a .NET console application using Visual Studio](with-visual-studio.md). - - The current build configuration is shown on the toolbar. The following toolbar image shows that Visual Studio is configured to compile the Debug version of the app: - - :::image type="content" source="./media/debugging-with-visual-studio/use-debug-configuration.png" alt-text="Visual Studio toolbar with debug highlighted"::: - -## Set a breakpoint - -A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is executed. - -1. Set a *breakpoint* on the line that displays the name, date, and time, by clicking in the left margin of the code window on that line. The left margin is to the left of the line numbers. Other ways to set a breakpoint are by placing the cursor in the line of code and then pressing F9 or choosing **Debug** > **Toggle Breakpoint** from the menu bar. - - As the following image shows, Visual Studio indicates the line on which the breakpoint is set by highlighting it and displaying a red dot in the left margin. - - :::image type="content" source="./media/debugging-with-visual-studio/set-breakpoint.png" alt-text="Visual Studio Program window with breakpoint set"::: - -1. Press F5 to run the program in Debug mode. Another way to start debugging is by choosing **Debug** > **Start Debugging** from the menu. - -1. Enter a string in the console window when the program prompts for a name, and then press Enter. - -1. Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method executes. The **Locals** window displays the values of variables that are defined in the currently executing method. - - :::image type="content" source="./media/debugging-with-visual-studio/breakpoint-hit.png" alt-text="Screenshot of a breakpoint in Visual Studio"::: - -## Use the Immediate window - -The **Immediate** window lets you interact with the application you're debugging. You can interactively change the value of variables to see how it affects your program. - -1. If the **Immediate** window is not visible, display it by choosing **Debug** > **Windows** > **Immediate**. - -1. Enter `name = "Gracie"` in the **Immediate** window and press the Enter key. - -1. Enter `currentDate = DateTime.Parse("2026-02-05T20:25:00Z").ToUniversalTime()` in the **Immediate** window and press the Enter key. - - The **Immediate** window displays the value of the string variable and the properties of the value. In addition, the values of the variables are updated in the **Locals** window. - - :::image type="content" source="./media/debugging-with-visual-studio/locals-immediate-window.png" alt-text="Locals and Immediate Windows in Visual Studio"::: - -1. Press F5 to continue program execution. Another way to continue is by choosing **Debug** > **Continue** from the menu. - - The values displayed in the console window correspond to the changes you made in the **Immediate** window. - -1. Press any key to exit the application and stop debugging. - -## Set a conditional breakpoint - -The program displays the string that the user enters. What happens if the user doesn't enter anything? You can test this with a useful debugging feature called a *conditional breakpoint*. - -1. Right-click on the red dot that represents the breakpoint. In the context menu, select **Conditions** to open the **Breakpoint Settings** dialog. Select the box for **Conditions** if it's not already selected. - - :::image type="content" source="./media/debugging-with-visual-studio/breakpoint-settings.png" alt-text="Editor showing breakpoint settings panel - C#"::: - -1. For the **Conditional Expression**, enter the following code in the text field. - - ```csharp - string.IsNullOrEmpty(name) - ``` - - ```vb - String.IsNullOrEmpty(name) - ``` - - 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. - -1. Select **Close** to close the dialog. - -1. Start the program with debugging by pressing F5. - -1. In the console window, press the Enter key when prompted to enter your name. - -1. Because the condition you specified (`name` is either `null` or ) has been satisfied, program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method executes. - -1. Select the **Locals** window, which shows the values of variables that are local to the currently executing method. In this case, `Main` is the currently executing method. Observe that the value of the `name` variable is `""`, or . - -1. Confirm the value is an empty string by entering the following statement in the **Immediate** window and pressing Enter. The result is `true`. - - ```csharp - ? name == String.Empty - ``` - - ```vb - ? String.IsNullOrEmpty(name) - ``` - - The question mark directs the immediate window to [evaluate an expression](/visualstudio/ide/reference/immediate-window#enter-commands). - - :::image type="content" source="./media/debugging-with-visual-studio/immediate-window-output.png" alt-text="Immediate Window returning a value of true after the statement is executed - C#"::: - -1. Press F5 to continue program execution. - -1. Press any key to close the console window 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 F9 or choosing **Debug > Toggle Breakpoint** while the line of code is selected. - -## Step through a program - -Visual Studio 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. - -1. Set a breakpoint on the line of code that displays the "What is your name?" prompt. - -1. Choose **Debug** > **Step Into**. Another way to debug one statement at a time is by pressing F11. - - Visual Studio highlights and displays an arrow beside the next line of execution. - - :::image type="content" source="./media/debugging-with-visual-studio/step-into-method.png" alt-text="Visual Studio step into method - C#"::: - - At this point, the **Locals** window shows that the `args` array is empty, and `name` and `currentDate` have default values. In addition, Visual Studio has opened a blank console window. - -1. Press F11. Visual Studio highlights the statement that includes the `name` variable assignment. The **Locals** window shows that `name` is `null`, and the console window displays the string "What is your name?". - -1. Respond to the prompt by entering a string in the console window and pressing Enter. The console is unresponsive, and the string you entered isn't displayed in the console window, but the method will nevertheless capture your input. - -1. Press F11. Visual Studio highlights the statement that includes the `currentDate` variable assignment. The **Locals** window shows the value returned by the call to the method. The console window also displays the string you entered at the prompt. - -1. Press F11. The **Locals** window shows the value of the `currentDate` variable after the assignment from the property. The console window is unchanged. - -1. Press F11. Visual Studio calls the method. The console window displays the formatted string. - -1. Choose **Debug** > **Step Out**. Another way to stop step-by-step execution is by pressing Shift+F11. - - The console window displays a message and waits for you to press a key. - -1. Press any key to close the console window and stop debugging. - -## Use Release build configuration - -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 sometimes negatively affect the behavior of an application. For example, compiler optimizations that are designed to improve performance can create race conditions in multithreaded applications. - -To build and test the Release version of your console application, change the build configuration on the toolbar from **Debug** to **Release**. - -:::image type="content" source="./media/debugging-with-visual-studio/use-release-configuration.png" alt-text="default Visual Studio toolbar with release highlighted"::: - -When you press F5 or choose **Build Solution** from the **Build** menu, Visual Studio compiles the Release version of the application. You can test it as you did the Debug version. - -## Next steps - -In this tutorial, you used Visual Studio debugging tools. In the next tutorial, you publish a deployable version of the app. - -> [!div class="nextstepaction"] -> [Publish a .NET console application using Visual Studio](publishing-with-visual-studio.md) diff --git a/docs/core/tutorials/index.md b/docs/core/tutorials/index.md index 4306002e1e468..16ba9a5943e33 100644 --- a/docs/core/tutorials/index.md +++ b/docs/core/tutorials/index.md @@ -1,7 +1,7 @@ --- title: .NET Tutorials description: Follow tutorials for learning .NET to build apps and libraries on Mac, Linux, and Windows. -ms.date: 10/23/2025 +ms.date: 02/12/2026 ai-usage: ai-assisted ms.custom: devdivchpfy22 titleSuffix: "" @@ -10,29 +10,22 @@ titleSuffix: "" The following tutorials show how to develop console apps and libraries for .NET Core, .NET 5, and later versions. For other types of applications, see [Tutorials for getting started with .NET](../../standard/get-started.md). -## Use Visual Studio +## Create apps and libraries -- [Create a console app](with-visual-studio.md) -- [Debug an app](debugging-with-visual-studio.md) -- [Publish an app](publishing-with-visual-studio.md) -- [Create a class library](library-with-visual-studio.md) -- [Unit test a class library](testing-library-with-visual-studio.md) -- [Install and use a package](/nuget/quickstart/install-and-use-a-package-in-visual-studio) -- [Create and publish a package](/nuget/quickstart/create-and-publish-a-package-using-visual-studio) -- [Create an F# console app](../../fsharp/get-started/get-started-visual-studio.md) +These tutorials support Visual Studio, Visual Studio Code, and GitHub Codespaces. Choose your preferred development environment using the zone pivot selector at the top of each article. -## Use Visual Studio Code - -Choose these tutorials if you want to use Visual Studio Code or another code editor. All of them use the CLI for .NET Core development tasks, so all except the debugging tutorial can be used with any code editor. - -- [Create a console app](with-visual-studio-code.md) -- [Debug an app](debugging-with-visual-studio-code.md) -- [Publish an app](publishing-with-visual-studio-code.md) -- [Create a class library](library-with-visual-studio-code.md) -- [Unit test a class library](testing-library-with-visual-studio-code.md) +- [Create a console app](create-console-app.md) +- [Debug an app](debug-console-app.md) +- [Publish an app](publish-console-app.md) +- [Create a class library](create-class-library.md) +- [Unit test a class library](test-class-library.md) - [Install and use a package](/nuget/quickstart/install-and-use-a-package-using-the-dotnet-cli) - [Create and publish a package](/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli) -- [Create an F# console app](../../fsharp/get-started/get-started-vscode.md) + +## F# tutorials + +- [Create an F# console app in Visual Studio](../../fsharp/get-started/get-started-visual-studio.md) +- [Create an F# console app in Visual Studio Code](../../fsharp/get-started/get-started-vscode.md) ## Advanced articles diff --git a/docs/core/tutorials/libraries.md b/docs/core/tutorials/libraries.md index 61476f046f9ee..6430dfbad27d4 100644 --- a/docs/core/tutorials/libraries.md +++ b/docs/core/tutorials/libraries.md @@ -7,7 +7,7 @@ ai-usage: ai-assisted --- # Develop libraries with the .NET CLI -This article covers how to write libraries for .NET using the .NET CLI. The CLI provides an efficient and low-level experience that works across any supported OS. You can still build libraries with Visual Studio, and if that's your preferred experience [refer to the Visual Studio guide](library-with-visual-studio.md). +This article covers how to write libraries for .NET using the .NET CLI. The CLI provides an efficient and low-level experience that works across any supported OS. You can still build libraries with Visual Studio, and if that's your preferred experience [refer to the Visual Studio guide](create-class-library.md). ## Prerequisites diff --git a/docs/core/tutorials/library-with-visual-studio-code.md b/docs/core/tutorials/library-with-visual-studio-code.md deleted file mode 100644 index fbb8b06e9f8a3..0000000000000 --- a/docs/core/tutorials/library-with-visual-studio-code.md +++ /dev/null @@ -1,141 +0,0 @@ ---- -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: 01/29/2026 ---- -# Tutorial: Create a .NET class library using Visual Studio Code - -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 10, it can be called by any application that targets .NET 10. This tutorial shows how to target .NET 10. - -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 - -[!INCLUDE [Prerequisites](../../../includes/prerequisites-basic-winget.md)] - -## Create a class library project - -Start by creating a .NET class library project named "StringLibrary" and an associated solution. A solution serves as a container for one or more projects. You'll add additional, related projects to the same solution. - -1. Start Visual Studio Code. - -1. Go to the Explorer view and select **Create .NET Project**. Alternatively, you can bring up the Command Palette using Ctrl+Shift+P (Command+Shift+P on MacOS) and then type ".NET" and find and select the .NET: New Project command. - -1. Choose the project template **Class Library**. - -1. Then select the location where you would like the new project to be created: Create a folder named `ClassLibraryProjects` and select it. - -1. Name the project **StringLibrary**. - -1. Select **.sln** as the solution file format. - -1. Select **Show all template options**. - -1. Next select **.NET 10**. Then select **Create Project**. - -1. In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. You can trust the authors because this folder only has files generated by .NET and added or modified by you. - -1. The project is created and *Class1.cs* opens. - -1. Replace the contents of *Class1.cs* with the following code: - - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs"::: - - The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The 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 class. - -1. Save the file. - -1. Expand **Solution Explorer** at the bottom of the **Explorer** view. - -1. Right click the solution in **Solution Explorer** and select **Build**, or open the Command Palette and select **.NET: Build** to build the solution and verify that the project compiles without error. - - The terminal output looks like the following example: - - ```output - Determining projects to restore... - All projects are up-to-date for restore. - StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net10.0\StringLibrary.dll - Build succeeded. - 0 Warning(s) - 0 Error(s) - Time Elapsed 00:00:02.78 - ``` - -## Add a console app to the solution - -Add a console application that uses the class library. The app will prompt the user to enter a string and report whether the string begins with an uppercase character. - -1. Right-click the solution in **Solution Explorer** and select **New Project**, or in the Command Palette select **.NET: New Project**. - -1. Select **Console App**. - -1. Give it the name **ShowCase**, select the default directory and select **Create Project**. - -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"::: - - 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. - - The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the Enter key without entering a string, the application ends, and the console window closes. - -1. Save your changes. - -## Add a project reference - -Initially, the new console app project doesn't have access to the class library. To allow it to call methods in the class library, create a project reference to the class library project. - -1. In **Solution Explorer** right click on the **ShowCase** project and select **Add Project Reference**. - -1. Select StringLibrary. - -> [!TIP] -> Alternatively, add the following to *ShowCase.csproj*: -> -> ```xml -> -> -> -> ``` - -## Run the app - -1. Use the top menu bar to select **Run** > **Run without debugging**. - -1. Select **C#**. - -1. Select **C#: ShowCase**. - - If you get an error that says no C# program is loaded, close the folder that you have open, and open the `ShowCase` folder. Then try running the app again. - -1. Try out the program by entering strings and pressing Enter, then press Enter to exit. - - The terminal output looks like the following example: - - ```output - Press only to exit; otherwise, enter a string and press : - - A string that starts with an uppercase letter - Input: A string that starts with an uppercase letter - Begins with uppercase? : Yes - - a string that starts with a lowercase letter - Input: a string that starts with a lowercase letter - Begins with uppercase? : No - ``` - -## Additional resources - -* [Develop libraries with the .NET CLI](libraries.md) -* [.NET Standard versions and the platforms they support](../../standard/net-standard.md). - -## Next steps - -In this tutorial, you created a library project and added a console app project that uses the library. In the next tutorial, you add a unit test project to the solution. - -> [!div class="nextstepaction"] -> [Test a .NET class library with .NET using Visual Studio Code](testing-library-with-visual-studio-code.md) diff --git a/docs/core/tutorials/library-with-visual-studio.md b/docs/core/tutorials/library-with-visual-studio.md deleted file mode 100644 index efb52170df955..0000000000000 --- a/docs/core/tutorials/library-with-visual-studio.md +++ /dev/null @@ -1,141 +0,0 @@ ---- -title: Create a .NET class library using Visual Studio -description: Learn how to create a .NET class library using Visual Studio. -ms.date: 01/13/2026 -ai-usage: ai-assisted -dev_langs: - - "csharp" - - "vb" -ms.custom: vs-dotnet ---- -# Tutorial: Create a .NET class library using Visual Studio - -In this tutorial, you create a simple class library that contains a single string-handling method. - -A *class library* defines types and methods that an application calls. If the library targets .NET Standard 2.0, any .NET implementation (including .NET Framework) that supports .NET Standard 2.0 can call it. If the library targets .NET 10, any application that targets .NET 10 can call it. This tutorial shows how to target .NET 10. - -When you create a class library, you can distribute it as a NuGet package or as a component bundled with the application that uses it. - -## Prerequisites - -- [Visual Studio 2026 or later](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=learn.microsoft.com&utm_campaign=inline+link) with the **.NET desktop development** workload installed. The .NET SDK is automatically installed when you select this workload. - - For more information, see [Install the .NET SDK with Visual Studio](../install/windows.md#install-with-visual-studio). - -## Create a solution - -Start by creating a blank solution to hold the class library project. A Visual Studio solution serves as a container for one or more projects. Add related projects to the same solution. - -To create the blank solution: - -1. Start Visual Studio. - -1. On the start window, choose **Create a new project**. - -1. On the **Create a new project** page, enter **solution** in the search box. Choose the **Blank Solution** template, and then choose **Next**. - - :::image type="content" source="media/library-with-visual-studio/blank-solution.png" alt-text="Blank solution template in Visual Studio"::: - -1. On the **Configure your new project** page, enter **ClassLibraryProjects** in the **Solution name** box. Then choose **Create**. - -## Create a class library project - -1. Add a new .NET class library project named **StringLibrary** to the solution. - - 1. Right-click on the solution in **Solution Explorer** and select **Add** > **New Project**. - - 1. On the **Add a new project** page, enter **library** in the search box. Choose **C#** or **Visual Basic** from the Language list, and then choose **All platforms** from the Platform list. Choose the **Class Library** template, and then choose **Next**. - - 1. On the **Configure your new project** page, enter **StringLibrary** in the **Project name** box, and then choose **Next**. - - 1. On the **Additional information** page, select **.NET 10**, and then choose **Create**. - -1. Check to make sure that the library targets the correct version of .NET. Right-click on the library project in **Solution Explorer**, and then select **Properties**. The **Target Framework** text box shows that the project targets .NET 10.0. - -1. If you're using Visual Basic, clear the text in the **Default namespace** text box. - - :::image type="content" source="./media/library-with-visual-studio/vb/library-project-properties.png" alt-text="Project properties for the class library"::: - - For each project, Visual Basic automatically creates a namespace that corresponds to the project name. In this tutorial, you define a top-level namespace by using the [`namespace`](../../visual-basic/language-reference/statements/namespace-statement.md) keyword in the code file. - -1. Replace the code in the code window for *Class1.cs* or *Class1.vb* with the following code, and save the file. If the language you want to use isn't shown, change the language selector at the top of the page. - - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs"::: - :::code language="vb" source="./snippets/library-with-visual-studio/vb/StringLibrary/Class1.vb"::: - - The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The 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 class. The question mark (`?`) after `string` in the C# code indicates that the string may be null. - -1. On the menu bar, select **Build** > **Build Solution** or press Ctrl+Shift+B to verify that the project compiles without error. - -## Add a console app to the solution - -Add a console application that uses the class library. The app prompts the user to enter a string and reports whether the string begins with an uppercase character. - -1. Add a new .NET console application named **ShowCase** to the solution. - - 1. Right-click on the solution in **Solution Explorer** and select **Add** > **New project**. - - 1. On the **Add a new project** page, enter **console** in the search box. Choose **C#** or **Visual Basic** from the Language list, and then choose **All platforms** from the Platform list. - - 1. Choose the **Console Application** template, and then choose **Next**. - - 1. On the **Configure your new project** page, enter **ShowCase** in the **Project name** box. Then choose **Next**. - - 1. On the **Additional information** page, select **.NET 10** in the **Framework** box. Then choose **Create**. - -1. In the code window for the *Program.cs* or *Program.vb* file, replace all of the code with the following code. - - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/ShowCase/Program.cs"::: - :::code language="vb" source="./snippets/library-with-visual-studio/vb/ShowCase/Program.vb"::: - - 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. - - The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the Enter key without entering a string, the application ends, and the console window closes. - -## Add a project reference - -Initially, the new console app project doesn't have access to the class library. To allow it to call methods in the class library, create a project reference to the class library project. - -1. In **Solution Explorer**, right-click the `ShowCase` project's **Dependencies** node, and select **Add Project Reference**. - - :::image type="content" source="media/library-with-visual-studio/add-reference-context-menu.png" alt-text="Add reference context menu in Visual Studio"::: - -1. In the **Reference Manager** dialog, select the **StringLibrary** project, and select **OK**. - - :::image type="content" source="media/library-with-visual-studio/manage-project-references.png" alt-text="Reference Manager dialog with StringLibrary selected"::: - -## Run the app - -1. In **Solution Explorer**, right-click the **ShowCase** project and select **Set as StartUp Project** in the context menu. - - :::image type="content" source="media/library-with-visual-studio/set-startup-project-context-menu.png" alt-text="Visual Studio project context menu to set startup project"::: - -1. Press Ctrl+F5 to compile and run the program without debugging. - -1. Try out the program by entering strings and pressing Enter, then press Enter to exit. - - :::image type="content" source="media/library-with-visual-studio/run-showcase.png" alt-text="Console window with ShowCase running"::: - -## Additional resources - -- [Develop libraries with the .NET CLI](libraries.md) -- [.NET Standard versions and the platforms they support](../../standard/net-standard.md). - -## Next steps - -In this tutorial, you created a class library. In the next tutorial, you learn how to unit test the class library. - -> [!div class="nextstepaction"] -> [Unit test a .NET class library using Visual Studio](testing-library-with-visual-studio.md) - -Or, you can skip automated unit testing and learn how to share the library by creating a NuGet package: - -> [!div class="nextstepaction"] -> [Create and publish a package using Visual Studio](/nuget/quickstart/create-and-publish-a-package-using-visual-studio) - -Or, learn how to publish a console app. If you publish the console app from the solution you created in this tutorial, the class library goes with it as a *.dll* file. - -> [!div class="nextstepaction"] -> [Publish a .NET console application using Visual Studio](publishing-with-visual-studio.md) diff --git a/docs/core/tutorials/media/create-class-library/add-reference-context-menu.png b/docs/core/tutorials/media/create-class-library/add-reference-context-menu.png new file mode 100644 index 0000000000000..2ed115bdb4161 Binary files /dev/null and b/docs/core/tutorials/media/create-class-library/add-reference-context-menu.png differ diff --git a/docs/core/tutorials/media/create-class-library/blank-solution.png b/docs/core/tutorials/media/create-class-library/blank-solution.png new file mode 100644 index 0000000000000..6f6e3a710fea7 Binary files /dev/null and b/docs/core/tutorials/media/create-class-library/blank-solution.png differ diff --git a/docs/core/tutorials/media/create-class-library/manage-project-references.png b/docs/core/tutorials/media/create-class-library/manage-project-references.png new file mode 100644 index 0000000000000..2cd07aa989de4 Binary files /dev/null and b/docs/core/tutorials/media/create-class-library/manage-project-references.png differ diff --git a/docs/core/tutorials/media/library-with-visual-studio/run-showcase.png b/docs/core/tutorials/media/create-class-library/run-showcase.png similarity index 100% rename from docs/core/tutorials/media/library-with-visual-studio/run-showcase.png rename to docs/core/tutorials/media/create-class-library/run-showcase.png diff --git a/docs/core/tutorials/media/create-class-library/set-startup-project-context-menu.png b/docs/core/tutorials/media/create-class-library/set-startup-project-context-menu.png new file mode 100644 index 0000000000000..da5a8aa3524c4 Binary files /dev/null and b/docs/core/tutorials/media/create-class-library/set-startup-project-context-menu.png differ diff --git a/docs/core/tutorials/media/create-class-library/vb/library-project-properties.png b/docs/core/tutorials/media/create-class-library/vb/library-project-properties.png new file mode 100644 index 0000000000000..2f9ee6f9010f6 Binary files /dev/null and b/docs/core/tutorials/media/create-class-library/vb/library-project-properties.png differ diff --git a/docs/core/tutorials/media/with-visual-studio/additional-information.png b/docs/core/tutorials/media/create-console-app/additional-information.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio/additional-information.png rename to docs/core/tutorials/media/create-console-app/additional-information.png diff --git a/docs/core/tutorials/media/with-visual-studio-code/codespaces-create-new-file.png b/docs/core/tutorials/media/create-console-app/codespaces-create-new-file.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio-code/codespaces-create-new-file.png rename to docs/core/tutorials/media/create-console-app/codespaces-create-new-file.png diff --git a/docs/core/tutorials/media/with-visual-studio/configure-new-project.png b/docs/core/tutorials/media/create-console-app/configure-new-project.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio/configure-new-project.png rename to docs/core/tutorials/media/create-console-app/configure-new-project.png diff --git a/docs/core/tutorials/media/with-visual-studio-code/create-codespace-on-main.png b/docs/core/tutorials/media/create-console-app/create-codespace-on-main.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio-code/create-codespace-on-main.png rename to docs/core/tutorials/media/create-console-app/create-codespace-on-main.png diff --git a/docs/core/tutorials/media/with-visual-studio-code/create-dotnet-project.png b/docs/core/tutorials/media/create-console-app/create-dotnet-project.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio-code/create-dotnet-project.png rename to docs/core/tutorials/media/create-console-app/create-dotnet-project.png diff --git a/docs/core/tutorials/media/with-visual-studio/create-new-project.png b/docs/core/tutorials/media/create-console-app/create-new-project.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio/create-new-project.png rename to docs/core/tutorials/media/create-console-app/create-new-project.png diff --git a/docs/core/tutorials/media/with-visual-studio/hello-world-update.png b/docs/core/tutorials/media/create-console-app/hello-world-update.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio/hello-world-update.png rename to docs/core/tutorials/media/create-console-app/hello-world-update.png diff --git a/docs/core/tutorials/media/with-visual-studio-code/run-program-class.png b/docs/core/tutorials/media/create-console-app/run-program-class.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio-code/run-program-class.png rename to docs/core/tutorials/media/create-console-app/run-program-class.png diff --git a/docs/core/tutorials/media/with-visual-studio/start-window.png b/docs/core/tutorials/media/create-console-app/start-window.png similarity index 100% rename from docs/core/tutorials/media/with-visual-studio/start-window.png rename to docs/core/tutorials/media/create-console-app/start-window.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-context-menu.png b/docs/core/tutorials/media/debug-console-app/breakpoint-context-menu.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-context-menu.png rename to docs/core/tutorials/media/debug-console-app/breakpoint-context-menu.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/breakpoint-hit.png b/docs/core/tutorials/media/debug-console-app/breakpoint-hit.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/breakpoint-hit.png rename to docs/core/tutorials/media/debug-console-app/breakpoint-hit.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-set.png b/docs/core/tutorials/media/debug-console-app/breakpoint-set.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-set.png rename to docs/core/tutorials/media/debug-console-app/breakpoint-set.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/breakpoint-settings.png b/docs/core/tutorials/media/debug-console-app/breakpoint-settings.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/breakpoint-settings.png rename to docs/core/tutorials/media/debug-console-app/breakpoint-settings.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/change-variable-values.png b/docs/core/tutorials/media/debug-console-app/change-variable-values.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/change-variable-values.png rename to docs/core/tutorials/media/debug-console-app/change-variable-values.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/changed-variable-values.png b/docs/core/tutorials/media/debug-console-app/changed-variable-values.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/changed-variable-values.png rename to docs/core/tutorials/media/debug-console-app/changed-variable-values.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-breakpoint-hit.png b/docs/core/tutorials/media/debug-console-app/codespaces-breakpoint-hit.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-breakpoint-hit.png rename to docs/core/tutorials/media/debug-console-app/codespaces-breakpoint-hit.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-breakpoint-set.png b/docs/core/tutorials/media/debug-console-app/codespaces-breakpoint-set.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-breakpoint-set.png rename to docs/core/tutorials/media/debug-console-app/codespaces-breakpoint-set.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-changed-variable-values.png b/docs/core/tutorials/media/debug-console-app/codespaces-changed-variable-values.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-changed-variable-values.png rename to docs/core/tutorials/media/debug-console-app/codespaces-changed-variable-values.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-select-debug-pane.png b/docs/core/tutorials/media/debug-console-app/codespaces-select-debug-pane.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/codespaces-select-debug-pane.png rename to docs/core/tutorials/media/debug-console-app/codespaces-select-debug-pane.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/conditional-expression.png b/docs/core/tutorials/media/debug-console-app/conditional-expression.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/conditional-expression.png rename to docs/core/tutorials/media/debug-console-app/conditional-expression.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/continue-debugging.png b/docs/core/tutorials/media/debug-console-app/continue-debugging.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/continue-debugging.png rename to docs/core/tutorials/media/debug-console-app/continue-debugging.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/immediate-window-output.png b/docs/core/tutorials/media/debug-console-app/immediate-window-output.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/immediate-window-output.png rename to docs/core/tutorials/media/debug-console-app/immediate-window-output.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/locals-immediate-window.png b/docs/core/tutorials/media/debug-console-app/locals-immediate-window.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/locals-immediate-window.png rename to docs/core/tutorials/media/debug-console-app/locals-immediate-window.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/run-modified-program.png b/docs/core/tutorials/media/debug-console-app/run-modified-program.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/run-modified-program.png rename to docs/core/tutorials/media/debug-console-app/run-modified-program.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/select-debug-console.png b/docs/core/tutorials/media/debug-console-app/select-debug-console.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/select-debug-console.png rename to docs/core/tutorials/media/debug-console-app/select-debug-console.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/select-debug-pane.png b/docs/core/tutorials/media/debug-console-app/select-debug-pane.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/select-debug-pane.png rename to docs/core/tutorials/media/debug-console-app/select-debug-pane.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/set-breakpoint.png b/docs/core/tutorials/media/debug-console-app/set-breakpoint.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/set-breakpoint.png rename to docs/core/tutorials/media/debug-console-app/set-breakpoint.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/start-debugging.png b/docs/core/tutorials/media/debug-console-app/start-debugging.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/start-debugging.png rename to docs/core/tutorials/media/debug-console-app/start-debugging.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/step-into-method.png b/docs/core/tutorials/media/debug-console-app/step-into-method.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/step-into-method.png rename to docs/core/tutorials/media/debug-console-app/step-into-method.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/step-into.png b/docs/core/tutorials/media/debug-console-app/step-into.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/step-into.png rename to docs/core/tutorials/media/debug-console-app/step-into.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/step-out.png b/docs/core/tutorials/media/debug-console-app/step-out.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio-code/step-out.png rename to docs/core/tutorials/media/debug-console-app/step-out.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/use-debug-configuration.png b/docs/core/tutorials/media/debug-console-app/use-debug-configuration.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/use-debug-configuration.png rename to docs/core/tutorials/media/debug-console-app/use-debug-configuration.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio/use-release-configuration.png b/docs/core/tutorials/media/debug-console-app/use-release-configuration.png similarity index 100% rename from docs/core/tutorials/media/debugging-with-visual-studio/use-release-configuration.png rename to docs/core/tutorials/media/debug-console-app/use-release-configuration.png diff --git a/docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-hit.png b/docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-hit.png deleted file mode 100644 index 74249ba9c5e54..0000000000000 Binary files a/docs/core/tutorials/media/debugging-with-visual-studio-code/breakpoint-hit.png and /dev/null differ diff --git a/docs/core/tutorials/media/library-with-visual-studio/add-reference-context-menu.png b/docs/core/tutorials/media/library-with-visual-studio/add-reference-context-menu.png deleted file mode 100644 index f131d1922a716..0000000000000 Binary files a/docs/core/tutorials/media/library-with-visual-studio/add-reference-context-menu.png and /dev/null differ diff --git a/docs/core/tutorials/media/library-with-visual-studio/blank-solution.png b/docs/core/tutorials/media/library-with-visual-studio/blank-solution.png deleted file mode 100644 index 5e7e9cb8385ee..0000000000000 Binary files a/docs/core/tutorials/media/library-with-visual-studio/blank-solution.png and /dev/null differ diff --git a/docs/core/tutorials/media/library-with-visual-studio/manage-project-references.png b/docs/core/tutorials/media/library-with-visual-studio/manage-project-references.png deleted file mode 100644 index bdfc4bee57046..0000000000000 Binary files a/docs/core/tutorials/media/library-with-visual-studio/manage-project-references.png and /dev/null differ diff --git a/docs/core/tutorials/media/library-with-visual-studio/set-startup-project-context-menu.png b/docs/core/tutorials/media/library-with-visual-studio/set-startup-project-context-menu.png deleted file mode 100644 index 0ab6809dd5e85..0000000000000 Binary files a/docs/core/tutorials/media/library-with-visual-studio/set-startup-project-context-menu.png and /dev/null differ diff --git a/docs/core/tutorials/media/library-with-visual-studio/vb/library-project-properties.png b/docs/core/tutorials/media/library-with-visual-studio/vb/library-project-properties.png deleted file mode 100644 index f815d6554f0f8..0000000000000 Binary files a/docs/core/tutorials/media/library-with-visual-studio/vb/library-project-properties.png and /dev/null differ diff --git a/docs/core/tutorials/media/publishing-with-visual-studio-code/codespaces-published-files-output.png b/docs/core/tutorials/media/publish-console-app/codespaces-published-files-output.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio-code/codespaces-published-files-output.png rename to docs/core/tutorials/media/publish-console-app/codespaces-published-files-output.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio-code/open-in-terminal.png b/docs/core/tutorials/media/publish-console-app/open-in-terminal.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio-code/open-in-terminal.png rename to docs/core/tutorials/media/publish-console-app/open-in-terminal.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/pick-publish-target.png b/docs/core/tutorials/media/publish-console-app/pick-publish-target.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/pick-publish-target.png rename to docs/core/tutorials/media/publish-console-app/pick-publish-target.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/pick-specific-publish-target.png b/docs/core/tutorials/media/publish-console-app/pick-specific-publish-target.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/pick-specific-publish-target.png rename to docs/core/tutorials/media/publish-console-app/pick-specific-publish-target.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/publish-context-menu.png b/docs/core/tutorials/media/publish-console-app/publish-context-menu.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/publish-context-menu.png rename to docs/core/tutorials/media/publish-console-app/publish-context-menu.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/publish-page-loc-tab.png b/docs/core/tutorials/media/publish-console-app/publish-page-loc-tab.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/publish-page-loc-tab.png rename to docs/core/tutorials/media/publish-console-app/publish-page-loc-tab.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/publish-page.png b/docs/core/tutorials/media/publish-console-app/publish-page.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/publish-page.png rename to docs/core/tutorials/media/publish-console-app/publish-page.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/published-files-output.png b/docs/core/tutorials/media/publish-console-app/published-files-output-visual-studio.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/published-files-output.png rename to docs/core/tutorials/media/publish-console-app/published-files-output-visual-studio.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio-code/published-files-output.png b/docs/core/tutorials/media/publish-console-app/published-files-output.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio-code/published-files-output.png rename to docs/core/tutorials/media/publish-console-app/published-files-output.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/show-all-files.png b/docs/core/tutorials/media/publish-console-app/show-all-files.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/show-all-files.png rename to docs/core/tutorials/media/publish-console-app/show-all-files.png diff --git a/docs/core/tutorials/media/publishing-with-visual-studio/use-release-configuration.png b/docs/core/tutorials/media/publish-console-app/use-release-configuration.png similarity index 100% rename from docs/core/tutorials/media/publishing-with-visual-studio/use-release-configuration.png rename to docs/core/tutorials/media/publish-console-app/use-release-configuration.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio-code/FailedTest.png b/docs/core/tutorials/media/test-class-library/FailedTest.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio-code/FailedTest.png rename to docs/core/tutorials/media/test-class-library/FailedTest.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio-code/TestingScreenshot.png b/docs/core/tutorials/media/test-class-library/TestingScreenshot.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio-code/TestingScreenshot.png rename to docs/core/tutorials/media/test-class-library/TestingScreenshot.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio/add-project-reference-string-library-test.png b/docs/core/tutorials/media/test-class-library/add-project-reference-string-library-test.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio/add-project-reference-string-library-test.png rename to docs/core/tutorials/media/test-class-library/add-project-reference-string-library-test.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio/additional-information-mstest.png b/docs/core/tutorials/media/test-class-library/additional-information-mstest.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio/additional-information-mstest.png rename to docs/core/tutorials/media/test-class-library/additional-information-mstest.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio/failed-test-detail.png b/docs/core/tutorials/media/test-class-library/failed-test-detail.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio/failed-test-detail.png rename to docs/core/tutorials/media/test-class-library/failed-test-detail.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio/failed-test-window.png b/docs/core/tutorials/media/test-class-library/failed-test-window.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio/failed-test-window.png rename to docs/core/tutorials/media/test-class-library/failed-test-window.png diff --git a/docs/core/tutorials/media/testing-library-with-visual-studio/test-explorer-window.png b/docs/core/tutorials/media/test-class-library/test-explorer-window.png similarity index 100% rename from docs/core/tutorials/media/testing-library-with-visual-studio/test-explorer-window.png rename to docs/core/tutorials/media/test-class-library/test-explorer-window.png diff --git a/docs/core/tutorials/publishing-with-visual-studio-code.md b/docs/core/tutorials/publish-console-app.md similarity index 58% rename from docs/core/tutorials/publishing-with-visual-studio-code.md rename to docs/core/tutorials/publish-console-app.md index 884e954b9cd75..10aabcce536d8 100644 --- a/docs/core/tutorials/publishing-with-visual-studio-code.md +++ b/docs/core/tutorials/publish-console-app.md @@ -1,26 +1,59 @@ --- -title: Publish a .NET console application using Visual Studio Code -description: Learn how to use Visual Studio Code and the .NET CLI to create the set of files that are needed to run a .NET application. -ms.date: 01/28/2026 +title: Publish a .NET console application +description: Learn how to publish a .NET console application using Visual Studio, Visual Studio Code, or the .NET CLI. +ms.date: 02/12/2026 +ai-usage: ai-assisted zone_pivot_groups: code-editor-set-one --- -# Tutorial: Publish a .NET console application using Visual Studio Code +# Tutorial: Publish a .NET console application This tutorial shows how to publish a console app so that other users can run it. Publishing creates the set of files that are needed to run an application. To deploy the files, copy them to the target machine. -The .NET CLI is used to publish the app. - ## Prerequisites -- 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). +- This tutorial works with the console app that you create in [Create a .NET console application](create-console-app.md). ## Publish the app +::: zone pivot="visualstudio" + +1. Start Visual Studio. + +1. Open the *HelloWorld* project that you created in [Create a .NET console application](create-console-app.md). + +1. Make sure that Visual Studio is using the Release build configuration. If necessary, change the build configuration setting on the toolbar from **Debug** to **Release**. + + :::image type="content" source="media/publish-console-app/use-release-configuration.png" alt-text="Visual Studio toolbar with release build selected."::: + +1. Right-click on the **HelloWorld** project (not the HelloWorld solution) and select **Publish** from the menu. + + :::image type="content" source="media/publish-console-app/publish-context-menu.png" alt-text="Visual Studio Publish context menu."::: + +1. On the **Target** tab of the **Publish** page, select **Folder**, and then select **Next**. + + :::image type="content" source="media/publish-console-app/pick-publish-target.png" alt-text="Pick a publish target in Visual Studio."::: + +1. On the **Specific Target** tab of the **Publish** page, select **Folder**, and then select **Next**. + + :::image type="content" source="media/publish-console-app/pick-specific-publish-target.png" alt-text="Pick the specific publish target in Visual Studio."::: + +1. On the **Location** tab of the **Publish** page, select **Finish**. + + :::image type="content" source="media/publish-console-app/publish-page-loc-tab.png" alt-text="Visual Studio Publish page Location tab."::: + +1. On the **Publish profile creation progress** page, select **Close**. + +1. On the **Publish** tab of the **Publish** window, select **Publish**. + + :::image type="content" source="media/publish-console-app/publish-page.png" alt-text="Visual Studio Publish window."::: + +::: zone-end + ::: zone pivot="vscode" 1. Start Visual Studio Code. -1. Open the *HelloWorld* project folder that you created in [Create a .NET console application using Visual Studio Code](with-visual-studio-code.md). +1. Open the *HelloWorld* project folder that you created in [Create a .NET console application](create-console-app.md). 1. Choose **View** > **Terminal** from the main menu. @@ -47,7 +80,7 @@ The .NET CLI is used to publish the app. ::: zone pivot="codespaces" -1. Open your GitHub Codespace that you created in [Create a .NET console application using Visual Studio Code](with-visual-studio-code.md). +1. Open your GitHub Codespace that you created in [Create a .NET console application](create-console-app.md). 1. Add the following line of code to the top of *HelloWorld.cs*: @@ -80,6 +113,44 @@ The .NET CLI is used to publish the app. ## Inspect the files +::: zone pivot="visualstudio" + +By default, the publishing process creates a framework-dependent deployment, which is a type of deployment where the published application runs on a machine that has the .NET runtime installed. Users can run the published app by double-clicking the executable or issuing the `dotnet HelloWorld.dll` command from a command prompt. + +In the following steps, you'll look at the files created by the publish process. + +1. In **Solution Explorer**, select **Show All Files**. + + :::image type="content" source="media/publish-console-app/show-all-files.png" alt-text="Solution Explorer option to Show All Files."::: + +1. In the project folder, expand *bin/Release/{net}/publish*. (Where {net} is the target framework folder, such as _net10.0_.) + + :::image type="content" source="media/publish-console-app/published-files-output-visual-studio.png" alt-text="Solution Explorer showing published files."::: + + As the image shows, the published output includes the following files: + + - *HelloWorld.deps.json* + + This is the application's runtime dependencies file. It defines the .NET components and the libraries (including the dynamic link library that contains your application) needed to run the app. For more information, see [Runtime configuration files](https://github.com/dotnet/cli/blob/85ca206d84633d658d7363894c4ea9d59e515c1a/Documentation/specs/runtime-configuration-file.md). + + - *HelloWorld.dll* + + This is the [framework-dependent deployment](../deploying/index.md#cross-platform-dll-deployment) version of the application. To execute this dynamic link library, enter `dotnet HelloWorld.dll` at a command prompt. This method of running the app works on any platform that has the .NET runtime installed. + + - *HelloWorld.exe* + + This is the [framework-dependent executable](../deploying/index.md#framework-dependent-deployment) version of the application. To run it, enter `HelloWorld.exe` at a command prompt. The file is operating-system-specific. + + - *HelloWorld.pdb* (optional for deployment) + + This is the debug symbols file. You aren't required to deploy this file along with your application, although you should save it in the event that you need to debug the published version of your application. + + - *HelloWorld.runtimeconfig.json* + + This is the application's runtime configuration file. It identifies the version of .NET that your application was built to run on. You can also add configuration options to it. For more information, see [.NET runtime configuration settings](../runtime-config/index.md#runtimeconfigjson). + +::: zone-end + ::: zone pivot="vscode" By default, the publishing process creates a framework-dependent deployment, which is a type of deployment where the published application runs on a machine that has the .NET runtime installed. To run the published app you can use the executable file or run the `dotnet HelloWorld.dll` command from a command prompt. @@ -90,7 +161,7 @@ In the following steps, you'll look at the files created by the publish process. 1. Expand *bin/Release/net10.0/publish*. - :::image type="content" source="media/publishing-with-visual-studio-code/published-files-output.png" alt-text="Explorer showing published files"::: + :::image type="content" source="media/publish-console-app/published-files-output.png" alt-text="Explorer showing published files"::: As the image shows, the published output includes the following files: @@ -126,7 +197,7 @@ In the following steps, you'll look at the files created by the publish process. 1. Expand *artifacts/HelloWorld*. - :::image type="content" source="media/publishing-with-visual-studio-code/codespaces-published-files-output.png" alt-text="Explorer showing published files"::: + :::image type="content" source="media/publish-console-app/codespaces-published-files-output.png" alt-text="Explorer showing published files"::: As the image shows, the published output includes the following files: @@ -156,11 +227,35 @@ In the following steps, you'll look at the files created by the publish process. ## Run the published app +::: zone pivot="visualstudio" + +1. In **Solution Explorer**, right-click the *publish* folder, and select **Copy Full Path**. + +1. Open a command prompt and navigate to the *publish* folder. To do that, enter `cd` and then paste the full path. For example: + + ```console + cd C:\Projects\HelloWorld\bin\Release\net10.0\publish\ + ``` + +1. Run the app by using the executable: + + 1. Enter `HelloWorld.exe` and press Enter. + + 1. Enter a name in response to the prompt, and press any key to exit. + +1. Run the app by using the `dotnet` command: + + 1. Enter `dotnet HelloWorld.dll` and press Enter. + + 1. Enter a name in response to the prompt, and press any key to exit. + +::: zone-end + ::: zone pivot="vscode" 1. In **Explorer**, right-click the *publish* folder (Ctrl-click on macOS), and select **Open in Integrated Terminal**. - :::image type="content" source="media/publishing-with-visual-studio-code/open-in-terminal.png" alt-text="Context menu showing Open in Terminal"::: + :::image type="content" source="media/publish-console-app/open-in-terminal.png" alt-text="Context menu showing Open in Terminal"::: 1. On Windows or Linux, run the app by using the executable. @@ -198,7 +293,7 @@ In the following steps, you'll look at the files created by the publish process. ## Cleanup resources -GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace. Then select "delete". +GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace. Then select "Delete". ::: zone-end @@ -207,4 +302,4 @@ GitHub automatically deletes your Codespace after 30 days of inactivity. If you In this tutorial, you published a console app. In the next tutorial, you create a class library. > [!div class="nextstepaction"] -> [Create a .NET class library using Visual Studio Code](library-with-visual-studio-code.md) +> [Create a .NET class library](create-class-library.md) diff --git a/docs/core/tutorials/publishing-with-visual-studio.md b/docs/core/tutorials/publishing-with-visual-studio.md deleted file mode 100644 index 8ff410ef7511c..0000000000000 --- a/docs/core/tutorials/publishing-with-visual-studio.md +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: Publish a .NET console application using Visual Studio -description: Learn how to use Visual Studio to create the set of files that are needed to run a .NET application. -ms.date: 01/14/2026 -ai-usage: ai-assisted -ms.custom: - - "vs-dotnet" - - sfi-image-nochange ---- -# Tutorial: Publish a .NET console application using Visual Studio - -This tutorial shows how to publish a console app so that other users can run it. Publishing creates the set of files that are needed to run your application. To deploy the files, copy them to the target machine. - -## Prerequisites - -This tutorial works with the console app that you create in [Create a .NET console application using Visual Studio](with-visual-studio.md). - -## Publish the app - -1. Start Visual Studio. - -1. Open the *HelloWorld* project that you created in [Create a .NET console application using Visual Studio](with-visual-studio.md). - -1. Make sure that Visual Studio is using the Release build configuration. If necessary, change the build configuration setting on the toolbar from **Debug** to **Release**. - - :::image type="content" source="media/publishing-with-visual-studio/use-release-configuration.png" alt-text="Visual Studio toolbar with release build selected."::: - -1. Right-click on the **HelloWorld** project (not the HelloWorld solution) and select **Publish** from the menu. - - :::image type="content" source="media/publishing-with-visual-studio/publish-context-menu.png" alt-text="Visual Studio Publish context menu."::: - -1. On the **Target** tab of the **Publish** page, select **Folder**, and then select **Next**. - - :::image type="content" source="media/publishing-with-visual-studio/pick-publish-target.png" alt-text="Pick a publish target in Visual Studio."::: - -1. On the **Specific Target** tab of the **Publish** page, select **Folder**, and then select **Next**. - - :::image type="content" source="media/publishing-with-visual-studio/pick-specific-publish-target.png" alt-text="Pick the specific publish target in Visual Studio."::: - -1. On the **Location** tab of the **Publish** page, select **Finish**. - - :::image type="content" source="media/publishing-with-visual-studio/publish-page-loc-tab.png" alt-text="Visual Studio Publish page Location tab."::: - -1. On the **Publish profile creation progress** page, select **Close**. - -1. On the **Publish** tab of the **Publish** window, select **Publish**. - - :::image type="content" source="media/publishing-with-visual-studio/publish-page.png" alt-text="Visual Studio Publish window."::: - -## Inspect the files - -By default, the publishing process creates a framework-dependent deployment, which is a type of deployment where the published application runs on a machine that has the .NET runtime installed. Users can run the published app by double-clicking the executable or issuing the `dotnet HelloWorld.dll` command from a command prompt. - -In the following steps, you'll look at the files created by the publish process. - -1. In **Solution Explorer**, select **Show All Files**. - - :::image type="content" source="media/publishing-with-visual-studio/show-all-files.png" alt-text="Solution Explorer option to Show All Files."::: - -1. In the project folder, expand *bin/Release/{net}/publish*. (Where {net} is the target framework folder, such as _net10.0_.) - - :::image type="content" source="media/publishing-with-visual-studio/published-files-output.png" alt-text="Solution Explorer showing published files."::: - - As the image shows, the published output includes the following files: - - - *HelloWorld.deps.json* - - This is the application's runtime dependencies file. It defines the .NET components and the libraries (including the dynamic link library that contains your application) needed to run the app. For more information, see [Runtime configuration files](https://github.com/dotnet/cli/blob/85ca206d84633d658d7363894c4ea9d59e515c1a/Documentation/specs/runtime-configuration-file.md). - - - *HelloWorld.dll* - - This is the [framework-dependent deployment](../deploying/index.md#cross-platform-dll-deployment) version of the application. To execute this dynamic link library, enter `dotnet HelloWorld.dll` at a command prompt. This method of running the app works on any platform that has the .NET runtime installed. - - - *HelloWorld.exe* - - This is the [framework-dependent executable](../deploying/index.md#framework-dependent-deployment) version of the application. To run it, enter `HelloWorld.exe` at a command prompt. The file is operating-system-specific. - - - *HelloWorld.pdb* (optional for deployment) - - This is the debug symbols file. You aren't required to deploy this file along with your application, although you should save it in the event that you need to debug the published version of your application. - - - *HelloWorld.runtimeconfig.json* - - This is the application's runtime configuration file. It identifies the version of .NET that your application was built to run on. You can also add configuration options to it. For more information, see [.NET runtime configuration settings](../runtime-config/index.md#runtimeconfigjson). - -## Run the published app - -1. In **Solution Explorer**, right-click the *publish* folder, and select **Copy Full Path**. - -1. Open a command prompt and navigate to the *publish* folder. To do that, enter `cd` and then paste the full path. For example: - - ```console - cd C:\Projects\HelloWorld\bin\Release\net10.0\publish\ - ``` - -1. Run the app by using the executable: - - 1. Enter `HelloWorld.exe` and press Enter. - - 1. Enter a name in response to the prompt, and press any key to exit. - -1. Run the app by using the `dotnet` command: - - 1. Enter `dotnet HelloWorld.dll` and press Enter. - - 1. Enter a name in response to the prompt, and press any key to exit. - -## Additional resources - -- [.NET application publishing overview](../deploying/index.md) -- [`dotnet publish`](../tools/dotnet-publish.md) -- [Tutorial: Publish a .NET console application using Visual Studio Code](publishing-with-visual-studio-code.md) -- [Use the .NET SDK in continuous integration (CI) environments](../../devops/dotnet-cli-and-continuous-integration.md) - -## Next steps - -In this tutorial, you published a console app. In the next tutorial, you create a class library. - -> [!div class="nextstepaction"] -> [Create a .NET class library using Visual Studio](library-with-visual-studio.md) diff --git a/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs b/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs new file mode 100644 index 0000000000000..23b98ee94d3db --- /dev/null +++ b/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs @@ -0,0 +1,30 @@ +using System; +using UtilityLibraries; + +int row = 0; + +do +{ + if (row == 0 || row >= 25) + ResetConsole(); + + string? input = Console.ReadLine(); + if (string.IsNullOrEmpty(input)) break; + Console.WriteLine($"Input: {input} {"Begins with uppercase? ",30}: " + + $"{(input.StartsWithUpper() ? "Yes" : "No")}{Environment.NewLine}"); + row += 3; +} while (true); +return; + +// Declare a ResetConsole local method +void ResetConsole() +{ + if (row > 0) + { + Console.WriteLine("Press any key to continue..."); + Console.ReadKey(); + } + Console.Clear(); + Console.WriteLine($"{Environment.NewLine}Press only to exit; otherwise, enter a string and press :{Environment.NewLine}"); + row = 3; +} \ No newline at end of file diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ShowCase/ShowCase.csproj b/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/ShowCase.csproj similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/csharp/ShowCase/ShowCase.csproj rename to docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/ShowCase.csproj diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs b/docs/core/tutorials/snippets/create-class-library/csharp/StringLibrary/Class1.cs similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs rename to docs/core/tutorials/snippets/create-class-library/csharp/StringLibrary/Class1.cs diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibrary/StringLibrary.csproj b/docs/core/tutorials/snippets/create-class-library/csharp/StringLibrary/StringLibrary.csproj similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibrary/StringLibrary.csproj rename to docs/core/tutorials/snippets/create-class-library/csharp/StringLibrary/StringLibrary.csproj diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/MSTestSettings.cs b/docs/core/tutorials/snippets/create-class-library/csharp/StringLibraryTest/MSTestSettings.cs similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/MSTestSettings.cs rename to docs/core/tutorials/snippets/create-class-library/csharp/StringLibraryTest/MSTestSettings.cs diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/StringLibraryTest.csproj b/docs/core/tutorials/snippets/create-class-library/csharp/StringLibraryTest/StringLibraryTest.csproj similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/StringLibraryTest.csproj rename to docs/core/tutorials/snippets/create-class-library/csharp/StringLibraryTest/StringLibraryTest.csproj diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/Test1.cs b/docs/core/tutorials/snippets/create-class-library/csharp/StringLibraryTest/Test1.cs similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/Test1.cs rename to docs/core/tutorials/snippets/create-class-library/csharp/StringLibraryTest/Test1.cs diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/ShowCase/Program.vb b/docs/core/tutorials/snippets/create-class-library/vb/ShowCase/Program.vb similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/vb/ShowCase/Program.vb rename to docs/core/tutorials/snippets/create-class-library/vb/ShowCase/Program.vb diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/ShowCase/ShowCase.vbproj b/docs/core/tutorials/snippets/create-class-library/vb/ShowCase/ShowCase.vbproj similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/vb/ShowCase/ShowCase.vbproj rename to docs/core/tutorials/snippets/create-class-library/vb/ShowCase/ShowCase.vbproj diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibrary/Class1.vb b/docs/core/tutorials/snippets/create-class-library/vb/StringLibrary/Class1.vb similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibrary/Class1.vb rename to docs/core/tutorials/snippets/create-class-library/vb/StringLibrary/Class1.vb diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibrary/StringLibrary.vbproj b/docs/core/tutorials/snippets/create-class-library/vb/StringLibrary/StringLibrary.vbproj similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibrary/StringLibrary.vbproj rename to docs/core/tutorials/snippets/create-class-library/vb/StringLibrary/StringLibrary.vbproj diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/StringLibraryTest.vbproj b/docs/core/tutorials/snippets/create-class-library/vb/StringLibraryTest/StringLibraryTest.vbproj similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/StringLibraryTest.vbproj rename to docs/core/tutorials/snippets/create-class-library/vb/StringLibraryTest/StringLibraryTest.vbproj diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/UnitTest1.vb b/docs/core/tutorials/snippets/create-class-library/vb/StringLibraryTest/UnitTest1.vb similarity index 100% rename from docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/UnitTest1.vb rename to docs/core/tutorials/snippets/create-class-library/vb/StringLibraryTest/UnitTest1.vb diff --git a/docs/core/tutorials/snippets/with-visual-studio/csharp/HelloWorld.csproj b/docs/core/tutorials/snippets/create-console-app/csharp/HelloWorld.csproj similarity index 100% rename from docs/core/tutorials/snippets/with-visual-studio/csharp/HelloWorld.csproj rename to docs/core/tutorials/snippets/create-console-app/csharp/HelloWorld.csproj diff --git a/docs/core/tutorials/snippets/with-visual-studio/csharp/Program.cs b/docs/core/tutorials/snippets/create-console-app/csharp/Program.cs similarity index 100% rename from docs/core/tutorials/snippets/with-visual-studio/csharp/Program.cs rename to docs/core/tutorials/snippets/create-console-app/csharp/Program.cs diff --git a/docs/core/tutorials/snippets/with-visual-studio/vb/HelloWorld.vbproj b/docs/core/tutorials/snippets/create-console-app/vb/HelloWorld.vbproj similarity index 100% rename from docs/core/tutorials/snippets/with-visual-studio/vb/HelloWorld.vbproj rename to docs/core/tutorials/snippets/create-console-app/vb/HelloWorld.vbproj diff --git a/docs/core/tutorials/snippets/with-visual-studio/vb/Program.vb b/docs/core/tutorials/snippets/create-console-app/vb/Program.vb similarity index 100% rename from docs/core/tutorials/snippets/with-visual-studio/vb/Program.vb rename to docs/core/tutorials/snippets/create-console-app/vb/Program.vb diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ClassLibraryProjects.sln b/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ClassLibraryProjects.sln deleted file mode 100644 index c42ddbab0bbbe..0000000000000 --- a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ClassLibraryProjects.sln +++ /dev/null @@ -1,62 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 -MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringLibrary", "StringLibrary\StringLibrary.csproj", "{416074E7-2C56-41FE-AC15-BBEAB23B8538}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShowCase", "ShowCase\ShowCase.csproj", "{67277DB1-F9E6-4515-8228-BE1DD9E26760}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringLibraryTest", "StringLibraryTest\StringLibraryTest.csproj", "{581A96A9-A9AF-4AC2-A7E9-3B26A5269765}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Debug|Any CPU.Build.0 = Debug|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Debug|x64.ActiveCfg = Debug|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Debug|x64.Build.0 = Debug|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Debug|x86.ActiveCfg = Debug|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Debug|x86.Build.0 = Debug|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Release|Any CPU.ActiveCfg = Release|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Release|Any CPU.Build.0 = Release|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Release|x64.ActiveCfg = Release|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Release|x64.Build.0 = Release|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Release|x86.ActiveCfg = Release|Any CPU - {416074E7-2C56-41FE-AC15-BBEAB23B8538}.Release|x86.Build.0 = Release|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Debug|Any CPU.Build.0 = Debug|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Debug|x64.ActiveCfg = Debug|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Debug|x64.Build.0 = Debug|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Debug|x86.ActiveCfg = Debug|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Debug|x86.Build.0 = Debug|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Release|Any CPU.ActiveCfg = Release|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Release|Any CPU.Build.0 = Release|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Release|x64.ActiveCfg = Release|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Release|x64.Build.0 = Release|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Release|x86.ActiveCfg = Release|Any CPU - {67277DB1-F9E6-4515-8228-BE1DD9E26760}.Release|x86.Build.0 = Release|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Debug|Any CPU.Build.0 = Debug|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Debug|x64.ActiveCfg = Debug|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Debug|x64.Build.0 = Debug|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Debug|x86.ActiveCfg = Debug|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Debug|x86.Build.0 = Debug|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Release|Any CPU.ActiveCfg = Release|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Release|Any CPU.Build.0 = Release|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Release|x64.ActiveCfg = Release|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Release|x64.Build.0 = Release|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Release|x86.ActiveCfg = Release|Any CPU - {581A96A9-A9AF-4AC2-A7E9-3B26A5269765}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ShowCase/Program.cs b/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ShowCase/Program.cs deleted file mode 100644 index 1b3eb80e8aa8e..0000000000000 --- a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/ShowCase/Program.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using UtilityLibraries; - -class Program -{ - static void Main(string[] args) - { - int row = 0; - - do - { - if (row == 0 || row >= 25) - ResetConsole(); - - string? input = Console.ReadLine(); - if (string.IsNullOrEmpty(input)) break; - Console.WriteLine($"Input: {input} {"Begins with uppercase? ",30}: " + - $"{(input.StartsWithUpper() ? "Yes" : "No")}{Environment.NewLine}"); - row += 3; - } while (true); - return; - - // Declare a ResetConsole local method - void ResetConsole() - { - if (row > 0) - { - Console.WriteLine("Press any key to continue..."); - Console.ReadKey(); - } - Console.Clear(); - Console.WriteLine($"{Environment.NewLine}Press only to exit; otherwise, enter a string and press :{Environment.NewLine}"); - row = 3; - } - } -} diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/ClassLibraryProjects.sln b/docs/core/tutorials/snippets/library-with-visual-studio/vb/ClassLibraryProjects.sln deleted file mode 100644 index b2c46f68ced9e..0000000000000 --- a/docs/core/tutorials/snippets/library-with-visual-studio/vb/ClassLibraryProjects.sln +++ /dev/null @@ -1,37 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "StringLibrary", "StringLibrary\StringLibrary.vbproj", "{487A968D-CC91-4AA4-8B0E-03824397B584}" -EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ShowCase", "ShowCase\ShowCase.vbproj", "{A5033F8D-6CB5-4918-913B-FE837CBE9682}" -EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "StringLibraryTest", "StringLibraryTest\StringLibraryTest.vbproj", "{FD86969C-F208-46E6-86C7-15A3709488D1}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {487A968D-CC91-4AA4-8B0E-03824397B584}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {487A968D-CC91-4AA4-8B0E-03824397B584}.Debug|Any CPU.Build.0 = Debug|Any CPU - {487A968D-CC91-4AA4-8B0E-03824397B584}.Release|Any CPU.ActiveCfg = Release|Any CPU - {487A968D-CC91-4AA4-8B0E-03824397B584}.Release|Any CPU.Build.0 = Release|Any CPU - {A5033F8D-6CB5-4918-913B-FE837CBE9682}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A5033F8D-6CB5-4918-913B-FE837CBE9682}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A5033F8D-6CB5-4918-913B-FE837CBE9682}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A5033F8D-6CB5-4918-913B-FE837CBE9682}.Release|Any CPU.Build.0 = Release|Any CPU - {FD86969C-F208-46E6-86C7-15A3709488D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FD86969C-F208-46E6-86C7-15A3709488D1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FD86969C-F208-46E6-86C7-15A3709488D1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FD86969C-F208-46E6-86C7-15A3709488D1}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {DC88EBD6-DDF7-4BF2-A779-D490A7C669B9} - EndGlobalSection -EndGlobal diff --git a/docs/core/tutorials/snippets/with-visual-studio-code/csharp/HelloWorld.cs b/docs/core/tutorials/snippets/with-visual-studio-code/csharp/HelloWorld.cs deleted file mode 100644 index 5255638abec71..0000000000000 --- a/docs/core/tutorials/snippets/with-visual-studio-code/csharp/HelloWorld.cs +++ /dev/null @@ -1,12 +0,0 @@ -// -Console.WriteLine("Hello, World!"); -// - -// -Console.WriteLine("What is your name?"); -var name = Console.ReadLine(); -var currentDate = DateTime.Now; -Console.WriteLine($"{Environment.NewLine}Hello, {name}, on {currentDate:d} at {currentDate:t}!"); -Console.Write($"{Environment.NewLine}Press Enter to exit..."); -Console.Read(); -// \ No newline at end of file diff --git a/docs/core/tutorials/snippets/with-visual-studio/csharp/Program-Read.cs b/docs/core/tutorials/snippets/with-visual-studio/csharp/Program-Read.cs deleted file mode 100644 index 199a6e9d1e18e..0000000000000 --- a/docs/core/tutorials/snippets/with-visual-studio/csharp/Program-Read.cs +++ /dev/null @@ -1,11 +0,0 @@ -//Variant of Program.cs that reads input from the debug console instead of the terminal -#if READ -// -Console.WriteLine("What is your name?"); -var name = Console.ReadLine(); -var currentDate = DateTime.Now; -Console.WriteLine($"{Environment.NewLine}Hello, {name}, on {currentDate:d} at {currentDate:t}!"); -Console.Write($"{Environment.NewLine}Press Enter to exit..."); -Console.Read(); -// -#endif diff --git a/docs/core/tutorials/test-class-library.md b/docs/core/tutorials/test-class-library.md new file mode 100644 index 0000000000000..47dc2596292dd --- /dev/null +++ b/docs/core/tutorials/test-class-library.md @@ -0,0 +1,426 @@ +--- +title: Test a .NET class library +description: Learn how to create and run a unit test project for a .NET class library using Visual Studio, Visual Studio Code, or GitHub Codespaces. +ms.date: 02/12/2026 +ai-usage: ai-assisted +zone_pivot_groups: code-editor-set-one +dev_langs: + - "csharp" + - "vb" +--- +# Tutorial: Test a .NET class library + +This tutorial shows how to automate unit testing by adding a test project to a solution. + +## Prerequisites + +This tutorial works with the solution that you create in [Create a .NET class library](create-class-library.md). + +## Create a unit test project + +Unit tests provide automated software testing during your development and publishing. [MSTest](https://github.com/Microsoft/testfx-docs) is one of three test frameworks you can choose from. The others are [xUnit](https://xunit.net/) and [nUnit](https://nunit.org/). + +::: zone pivot="visualstudio" + +1. Start Visual Studio. + +1. Open the `ClassLibraryProjects` solution you created in [Create a .NET class library](create-class-library.md). + +1. Add a new unit test project named "StringLibraryTest" to the solution. + + 1. Right-click on the solution in **Solution Explorer** and select **Add** > **New project**. + + 1. On the **Add a new project** page, enter **mstest** in the search box. Choose **C#** or **Visual Basic** from the Language list, and then choose **All platforms** from the Platform list. + + 1. Choose the **MSTest Test Project** template, and then choose **Next**. + + 1. On the **Configure your new project** page, enter **StringLibraryTest** in the **Project name** box. Then choose **Next**. + + 1. On the **Additional information** page, select **.NET 10** in the **Framework** box, select **Microsoft.Testing.Platform** for the **Test runner**, and then choose **Create**. + + :::image type="content" source="./media/test-class-library/additional-information-mstest.png" alt-text="Enter additional information for the MSTest Test Project"::: + +1. Visual Studio creates the project and opens the class file in the code window with the following code. If the language you want to use isn't shown, change the language selector at the top of the page. + + ```csharp + namespace StringLibraryTest + { + + [TestClass] + public sealed class Test1 + { + [TestMethod] + public void TestMethod1() + { + } + } + } + ``` + + ```vb + Imports Microsoft.VisualStudio.TestTools.UnitTesting + + Namespace StringLibraryTest + + Public Class Test1 + + Sub TestSub() + + End Sub + End Class + End Namespace + ``` + + The source code created by the unit test template does the following: + + - Includes in the StringLibraryTest project file in C#, and imports in Visual Basic. + - Applies the attribute to the `Test1` class. + - Applies the attribute to define `TestMethod1` in C# or `TestSub` in Visual Basic. + + Each method tagged with [[TestMethod]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) in a test class tagged with [[TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) executes automatically when the unit test runs. + +::: zone-end + +::: zone pivot="vscode" + +1. Start Visual Studio Code. + +1. Open the `ClassLibraryProjects` solution you created in [Create a .NET class library](create-class-library.md). + +1. From **Solution Explorer**, select **New Project**, or from the Command Palette select **.NET: New Project**. + +1. Select **MSTest Test Project**, name it "StringLibraryTest", select the default directory, and select **Create Project**. + + The project template creates *StringLibraryTest/Test1.cs* with the following code: + + ```csharp + namespace StringLibraryTest; + + [TestClass] + public class Test1 + { + [TestMethod] + public void TestMethod1() + { + } + } + ``` + + The source code created by the unit test template does the following: + + - It applies the attribute to the `Test1` class. + - It applies the attribute to define `TestMethod1`. + - It imports the namespace, which contains the types used for unit testing. The namespace is imported via a `global using` directive in *GlobalUsings.cs*. + + Each method tagged with [[TestMethod]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) in a test class tagged with [[TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) is run automatically when the unit test is invoked. + +::: zone-end + +::: zone pivot="codespaces" + +1. Open the terminal and navigate to the tutorials folder containing the StringLibrary and ShowCase projects. + +1. Create a new MSTest test project: + + ```dotnetcli + dotnet new mstest -n StringLibraryTest + ``` + + The project template creates *StringLibraryTest/Test1.cs* with the following code: + + ```csharp + namespace StringLibraryTest; + + [TestClass] + public class Test1 + { + [TestMethod] + public void TestMethod1() + { + } + } + ``` + + The source code created by the unit test template does the following: + + - It applies the attribute to the `Test1` class. + - It applies the attribute to define `TestMethod1`. + - It imports the namespace, which contains the types used for unit testing. + + Each method tagged with [[TestMethod]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) in a test class tagged with [[TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) is run automatically when the unit test is invoked. + +::: zone-end + +## Add a project reference + +For the test project to work with the `StringLibrary` class, add a reference in the `StringLibraryTest` project to the `StringLibrary` project. + +::: zone pivot="visualstudio" + +1. In **Solution Explorer**, right-click the **Dependencies** node of the **StringLibraryTest** project and select **Add Project Reference** from the context menu. + +1. In the **Reference Manager** dialog, select the box next to **StringLibrary**. + + :::image type="content" source="./media/test-class-library/add-project-reference-string-library-test.png" alt-text="Add StringLibrary as a project reference for StringLibraryTest."::: + +1. Select **OK**. + +::: zone-end + +::: zone pivot="vscode" + +1. From **Solution Explorer** right click on the 'StringLibraryTest' Project and select **Add Project Reference**. + +1. Select "StringLibrary". + +::: zone-end + +::: zone pivot="codespaces" + +1. Navigate to the StringLibraryTest folder and add the project reference: + + ```bash + cd StringLibraryTest + dotnet add reference ../StringLibrary/StringLibrary.csproj + ``` + +::: zone-end + +## Add and run unit test methods + +When a unit test runs, each method marked with the attribute in a class marked with the attribute executes automatically. A test method ends when the first failure is found or when all tests contained in the method succeed. + +The most common tests call members of the class. Many assert methods include at least two parameters, one of which is the expected test result and the other of which is the actual test result. Some of the `Assert` class's most frequently called methods are shown in the following table: + +| Assert methods | Function | +| ------------------ | -------- | +| `Assert.AreEqual` | Verifies that two values or objects are equal. The assert fails if the values or objects aren't equal. | +| `Assert.AreSame` | Verifies that two object variables refer to the same object. The assert fails if the variables refer to different objects. | +| `Assert.IsFalse` | Verifies that a condition is `false`. The assert fails if the condition is `true`. | +| `Assert.IsNotNull` | Verifies that an object isn't `null`. The assert fails if the object is `null`. | + +You can also use the method in a test method to indicate the type of exception it's expected to throw. The test fails if the specified exception isn't thrown. + +In testing the `StringLibrary.StartsWithUpper` method, you want to provide a number of strings that begin with an uppercase character. You expect the method to return `true` in these cases, so you can call the method. Similarly, you want to provide a number of strings that begin with something other than an uppercase character. You expect the method to return `false` in these cases, so you can call the method. + +Since your library method handles strings, you also want to make sure that it successfully handles an [empty string (`String.Empty`)](xref:System.String.Empty) and a `null` string. An empty string is one that has no characters and whose is 0. A `null` string is one that hasn't been initialized. You can call `StartsWithUpper` directly as a static method and pass a single argument. Or you can call `StartsWithUpper` as an extension method on a `string` variable assigned to `null`. + +You'll define three methods, each of which calls an method for each element in a string array. You'll call a method overload that lets you specify an error message to be displayed in case of test failure. The message identifies the string that caused the failure. + +To create the test methods: + +::: zone pivot="visualstudio" + +1. In the *Test1.cs* or *Test1.vb* code window, replace the code with the following code: + + :::code language="csharp" source="./snippets/create-class-library/csharp/StringLibraryTest/Test1.cs"::: + :::code language="vb" source="./snippets/create-class-library/vb/StringLibraryTest/UnitTest1.vb"::: + + The test of uppercase characters in the `TestStartsWithUpper` method includes the Greek capital letter alpha (U+0391) and the Cyrillic capital letter EM (U+041C). The test of lowercase characters in the `TestDoesNotStartWithUpper` method includes the Greek small letter alpha (U+03B1) and the Cyrillic small letter Ghe (U+0433). + +1. On the menu bar, select **File** > **Save Test1.cs As** or **File** > **Save Test1.vb As**. In the **Save File As** dialog, select the arrow beside the **Save** button, and select **Save with Encoding**. + +1. In the **Confirm Save As** dialog, select the **Yes** button to save the file. + +1. In the **Advanced Save Options** dialog, select **Unicode (UTF-8 with signature) - Codepage 65001** from the **Encoding** drop-down list and select **OK**. + + If you fail to save your source code as a UTF8-encoded file, Visual Studio might save it as an ASCII file. When that happens, the runtime doesn't accurately decode the UTF8 characters outside of the ASCII range, and the test results aren't correct. + +1. On the menu bar, select **Test** > **Run All Tests**. If the **Test Explorer** window doesn't open, open it by choosing **Test** > **Test Explorer**. The three tests are listed in the **Passed Tests** section, and the **Summary** section reports the result of the test run. + + :::image type="content" source="./media/test-class-library/test-explorer-window.png" alt-text="Test Explorer window with passing tests"::: + +::: zone-end + +::: zone pivot="vscode" + +1. Open *StringLibraryTest/Test1.cs* and replace all of the code with the following code. + + :::code language="csharp" source="./snippets/create-class-library/csharp/StringLibraryTest/Test1.cs"::: + + The test of uppercase characters in the `TestStartsWithUpper` method includes the Greek capital letter alpha (U+0391) and the Cyrillic capital letter EM (U+041C). The test of lowercase characters in the `TestDoesNotStartWithUpper` method includes the Greek small letter alpha (U+03B1) and the Cyrillic small letter Ghe (U+0433). + +1. Save your changes. + +## Build and run your tests + +1. In **Solution Explorer**, right-click the solution and select **Build** or from the Command Palette, select **.NET: Build**. + +1. Select the **Testing** window, select **Run Tests** or from the Command Palette, select **Test: Run all Tests**. + + :::image type="content" source="media/test-class-library/testingScreenshot.png" alt-text="Visual Studio Code Test Explorer"::: + +::: zone-end + +::: zone pivot="codespaces" + +1. Open *StringLibraryTest/Test1.cs* and replace all of the code with the following code: + + :::code language="csharp" source="./snippets/create-class-library/csharp/StringLibraryTest/Test1.cs"::: + + The test of uppercase characters in the `TestStartsWithUpper` method includes the Greek capital letter alpha (U+0391) and the Cyrillic capital letter EM (U+041C). The test of lowercase characters in the `TestDoesNotStartWithUpper` method includes the Greek small letter alpha (U+03B1) and the Cyrillic small letter Ghe (U+0433). + +1. Save your changes and run the tests: + + ```dotnetcli + dotnet test + ``` + + The tests should pass. + +::: zone-end + +## Handle test failures + +If you're doing test-driven development (TDD), you write tests first and they fail the first time you run them. Then you add code to the app that makes the test succeed. For this tutorial, you created the test after writing the app code that it validates, so you haven't seen the test fail. To validate that a test fails when you expect it to fail, add an invalid value to the test input. + +1. Modify the `words` array in the `TestDoesNotStartWithUpper` method to include the string "Error". + + ```csharp + string[] words = { "alphabet", "Error", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство", + "1234", ".", ";", " " }; + ``` + + ```vb + Dim words() As String = { "alphabet", "Error", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство", + "1234", ".", ";", " " } + + ``` + +::: zone pivot="visualstudio" + +1. Run the test by selecting **Test** > **Run All Tests** from the menu bar. The **Test Explorer** window indicates that two tests succeeded and one failed. + + :::image type="content" source="./media/test-class-library/failed-test-window.png" alt-text="Test Explorer window with failing tests"::: + +1. Select the failed test, `TestDoesNotStartWith`. + + The **Test Explorer** window displays the message produced by the assert: "Assert.IsFalse failed. Expected for 'Error': false; actual: True." Because of the failure, the strings in the array after "Error" weren't tested. + + :::image type="content" source="./media/test-class-library/failed-test-detail.png" alt-text="Test Explorer window showing the IsFalse assertion failure"::: + +::: zone-end + +::: zone pivot="vscode" + +1. Run the tests by clicking on the green error next to the test in the editor. + + The output shows that the test fails, and it provides an error message for the failed test: "Assert.IsFalse failed. Expected for 'Error': false; actual: True". Because of the failure, no strings in the array after "Error" were tested. + + :::image type="content" source="media/test-class-library/failedTest.png" alt-text="Visual Studio Code Failed Test"::: + +::: zone-end + +::: zone pivot="codespaces" + +1. Run the tests: + + ```dotnetcli + dotnet test + ``` + + The output shows that the test fails, and it provides an error message for the failed test: "Assert.IsFalse failed. Expected for 'Error': false; actual: True". Because of the failure, no strings in the array after "Error" were tested. + +::: zone-end + +1. Remove the string "Error" that you added. + +1. Rerun the test and the tests pass. + +## Test the Release version of the library + +Now that the tests have all passed when running the Debug build of the library, run the tests an additional time against the Release build of the library. A number of factors, including compiler optimizations, can sometimes produce different behavior between Debug and Release builds. + +::: zone pivot="visualstudio" + +To test the Release build: + +1. In the Visual Studio toolbar, change the build configuration from **Debug** to **Release**. + +1. In **Solution Explorer**, right-click the **StringLibrary** project and select **Build** from the context menu to recompile the library. + +1. Run the unit tests by choosing **Test** > **Run All Tests** from the menu bar. The tests pass. + +::: zone-end + +::: zone pivot="vscode" + +Run the tests with the Release build configuration: + +```dotnetcli +dotnet test StringLibraryTest/StringLibraryTest.csproj --configuration Release +``` + +The tests pass. + +::: zone-end + +::: zone pivot="codespaces" + +Run the tests with the Release build configuration: + +```dotnetcli +dotnet test --configuration Release +``` + +The tests pass. + +::: zone-end + +## Debug tests + +::: zone pivot="visualstudio" + +If you're using Visual Studio as your IDE, you can use the same process shown in [Tutorial: Debug a .NET console application](debug-console-app.md) to debug code using your unit test project. Instead of starting the *ShowCase* app project, right-click the **StringLibraryTests** project, and select **Debug Tests** from the context menu. + +Visual Studio starts the test project with the debugger attached. Execution stops at any breakpoint you've added to the test project or the underlying library code. + +::: zone-end + +::: zone pivot="vscode,codespaces" + +If you're using Visual Studio Code as your IDE, you can use the same process shown in [Debug a .NET console application](debug-console-app.md) to debug code using your unit test project. Instead of starting the *ShowCase* app project, open *StringLibraryTest/Test1.cs*, and select **Debug Tests in current file** between lines 7 and 8. If you're unable to find it, press Ctrl+Shift+P to open the command palette and enter **Reload Window**. + +Visual Studio Code starts the test project with the debugger attached. Execution will stop at any breakpoint you've added to the test project or the underlying library code. + +::: zone-end + +## Additional resources + +::: zone pivot="visualstudio" + +- [Unit test basics - Visual Studio](/visualstudio/test/unit-test-basics) +- [Unit testing in .NET](../testing/index.md) + +::: zone-end + +::: zone pivot="vscode,codespaces" + +- [Unit testing in .NET](../testing/index.md) + +::: zone-end + +::: zone pivot="codespaces" + +## Cleanup resources + +GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace. Then select "Delete". + +::: zone-end + +## Next steps + +In this tutorial, you unit tested a class library. You can make the library available to others by publishing it to [NuGet](https://nuget.org) as a package. To learn how, follow a NuGet tutorial: + +> [!div class="nextstepaction"] +> [Create and publish a package using the dotnet CLI](/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli) + +If you publish a library as a NuGet package, others can install and use it. To learn how, follow a NuGet tutorial: + +> [!div class="nextstepaction"] +> [Install and use a package using the dotnet CLI](/nuget/quickstart/install-and-use-a-package-using-the-dotnet-cli) + +A library doesn't have to be distributed as a package. It can be bundled with a console app that uses it. To learn how to publish a console app, see the earlier tutorial in this series: + +> [!div class="nextstepaction"] +> [Publish a .NET console application](publish-console-app.md) diff --git a/docs/core/tutorials/testing-library-with-visual-studio-code.md b/docs/core/tutorials/testing-library-with-visual-studio-code.md deleted file mode 100644 index 11dd5467810ed..0000000000000 --- a/docs/core/tutorials/testing-library-with-visual-studio-code.md +++ /dev/null @@ -1,160 +0,0 @@ ---- -title: Test a .NET class library using Visual Studio Code -description: Learn how to use Visual Studio Code and run a unit test project for a .NET class library. -ms.date: 10/23/2025 -ai-usage: ai-assisted ---- -# Tutorial: Test a .NET class library using Visual Studio Code - -This tutorial shows how to automate unit testing by adding a test project to a solution. - -## Prerequisites - -This tutorial works with the solution that you create in [Create a .NET class library using Visual Studio Code](library-with-visual-studio-code.md). - -## Create a unit test project - -Unit tests provide automated software testing during your development and publishing. The testing framework that you use in this tutorial is MSTest. [MSTest](https://github.com/Microsoft/testfx-docs) is one of three test frameworks you can choose from. The others are [xUnit](https://xunit.net/) and [nUnit](https://nunit.org/). - -1. Start Visual Studio Code. - -1. Open the `ClassLibraryProjects` solution you created in [Create a .NET class library using Visual Studio Code](library-with-visual-studio-code.md). - -1. From **Solution Explorer**, select **New Project**, or from the Command Palette select **.NET: New Project**. - -1. Select **MSTest Test Project**, name it "StringLibraryTest", select the default directory, and select **Create Project**. - - The project template creates a *UnitTest1.cs* file with the following code: - - ```csharp - namespace StringLibraryTest; - - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } - ``` - - The source code created by the unit test template does the following: - - - It applies the attribute to the `UnitTest1` class. - - It applies the attribute to define `TestMethod1`. - - It imports the namespace, which contains the types used for unit testing. The namespace is imported via a `global using` directive in *GlobalUsings.cs*. - - Each method tagged with [[TestMethod]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) in a test class tagged with [[TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) is run automatically when the unit test is invoked. - -## Add a project reference - -For the test project to work with the `StringLibrary` class, add a reference in the `StringLibraryTest` project to the `StringLibrary` project. - -1. From **Solution Explorer** right click on the 'StringLibraryTest' Project and select **Add Project Reference**. - -1. Select "StringLibrary". - -## Add and run unit test methods - -When Visual Studio invokes a unit test, it runs each method that is marked with the attribute in a class that is marked with the attribute. A test method ends when the first failure is found or when all tests contained in the method have succeeded. - -The most common tests call members of the class. Many assert methods include at least two parameters, one of which is the expected test result and the other of which is the actual test result. Some of the `Assert` class's most frequently called methods are shown in the following table: - -| Assert methods | Function | -| ------------------ | -------- | -| `Assert.AreEqual` | Verifies that two values or objects are equal. The assert fails if the values or objects aren't equal. | -| `Assert.AreSame` | Verifies that two object variables refer to the same object. The assert fails if the variables refer to different objects. | -| `Assert.IsFalse` | Verifies that a condition is `false`. The assert fails if the condition is `true`. | -| `Assert.IsNotNull` | Verifies that an object isn't `null`. The assert fails if the object is `null`. | - -You can also use the method in a test method to indicate the type of exception it's expected to throw. The test fails if the specified exception isn't thrown. - -In testing the `StringLibrary.StartsWithUpper` method, you want to provide a number of strings that begin with an uppercase character. You expect the method to return `true` in these cases, so you can call the method. Similarly, you want to provide a number of strings that begin with something other than an uppercase character. You expect the method to return `false` in these cases, so you can call the method. - -Since your library method handles strings, you also want to make sure that it successfully handles an [empty string (`String.Empty`)](xref:System.String.Empty) and a `null` string. An empty string is one that has no characters and whose is 0. A `null` string is one that hasn't been initialized. You can call `StartsWithUpper` directly as a static method and pass a single argument. Or you can call `StartsWithUpper` as an extension method on a `string` variable assigned to `null`. - -You'll define three methods, each of which calls an method for each element in a string array. You'll call a method overload that lets you specify an error message to be displayed in case of test failure. The message identifies the string that caused the failure. - -To create the test methods: - -1. Open *StringLibraryTest/UnitTest1.cs* and replace all of the code with the following code. - - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibraryTest/Test1.cs"::: - - The test of uppercase characters in the `TestStartsWithUpper` method includes the Greek capital letter alpha (U+0391) and the Cyrillic capital letter EM (U+041C). The test of lowercase characters in the `TestDoesNotStartWithUpper` method includes the Greek small letter alpha (U+03B1) and the Cyrillic small letter Ghe (U+0433). - -1. Save your changes. - -## Build and Run your Tests - -1. In **Solution Explorer**, right-click the solution and select **Build** or from the Command Palette, select **.NET: Build**. - -1. Select the **Testing** window, select **Run Tests** or from the Command Palette, select **Test: Run all Tests**. - - :::image type="content" source="media/testing-library-with-visual-studio-code/testingScreenshot.png" alt-text="Visual Studio Code Test Explorer"::: - -## Handle test failures - -If you're doing test-driven development (TDD), you write tests first and they fail the first time you run them. Then you add code to the app that makes the test succeed. For this tutorial, you created the test after writing the app code that it validates, so you haven't seen the test fail. To validate that a test fails when you expect it to fail, add an invalid value to the test input. - -1. Modify the `words` array in the `TestDoesNotStartWithUpper` method to include the string "Error". - - ```csharp - string[] words = { "alphabet", "Error", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство", - "1234", ".", ";", " " }; - ``` - -1. Run the tests by clicking on the green error next to the test in the editor. - - The output shows that the test fails, and it provides an error message for the failed test: "Assert.IsFalse failed. Expected for 'Error': false; actual: True". Because of the failure, no strings in the array after "Error" were tested. - - :::image type="content" source="media/testing-library-with-visual-studio-code/failedTest.png" alt-text="Visual Studio Code Failed Test"::: - -1. Remove the string "Error" that you added in step. - -1. Rerun the test and the tests pass. - -## Test the Release version of the library - -Now that the tests have all passed when running the Debug build of the library, run the tests an additional time against the Release build of the library. A number of factors, including compiler optimizations, can sometimes produce different behavior between Debug and Release builds. - -1. Run the tests with the Release build configuration: - - ```dotnetcli - dotnet test StringLibraryTest/StringLibraryTest.csproj --configuration Release - ``` - - The tests pass. - -## Debug tests - -If you're using Visual Studio Code as your IDE, you can use the same process shown in [Debug a .NET console application using Visual Studio Code](debugging-with-visual-studio-code.md) to debug code using your unit test project. Instead of starting the *ShowCase* app project, open *StringLibraryTest/UnitTest1.cs*, and select **Debug Tests in current file** between lines 7 and 8. If you're unable to find it, press Ctrl+Shift+P to open the command palette and enter **Reload Window**. - -Visual Studio Code starts the test project with the debugger attached. Execution will stop at any breakpoint you've added to the test project or the underlying library code. - -## Additional resources - -- [Unit testing in .NET](../testing/index.md) - -## Next steps - -In this tutorial, you unit tested a class library. You can make the library available to others by publishing it to [NuGet](https://nuget.org) as a package. To learn how, follow a NuGet tutorial: - -> [!div class="nextstepaction"] -> [Create and publish a package using the dotnet CLI](/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli) - -If you publish a library as a NuGet package, others can install and use it. To learn how, follow a NuGet tutorial: - -> [!div class="nextstepaction"] -> [Install and use a package using the dotnet CLI](/nuget/quickstart/install-and-use-a-package-using-the-dotnet-cli) - -A library doesn't have to be distributed as a package. It can be bundled with a console app that uses it. To learn how to publish a console app, see the earlier tutorial in this series: - -> [!div class="nextstepaction"] -> [Publish a .NET console application using Visual Studio Code](publishing-with-visual-studio-code.md) - -The Visual Studio Code extension C# Dev Kit provides more tools for developing C# apps and libraries: - -> [!div class="nextstepaction"] -> [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp-dev-kit) diff --git a/docs/core/tutorials/testing-library-with-visual-studio.md b/docs/core/tutorials/testing-library-with-visual-studio.md deleted file mode 100644 index 716a2ba3f7258..0000000000000 --- a/docs/core/tutorials/testing-library-with-visual-studio.md +++ /dev/null @@ -1,201 +0,0 @@ ---- -title: Test a .NET class library using Visual Studio -description: Learn how to use Visual Studio to create and run a unit test project for a .NET class library. -ms.date: 01/14/2026 -ai-usage: ai-assisted -dev_langs: - - "csharp" - - "vb" -ms.custom: "vs-dotnet" ---- -# Tutorial: Test a .NET class library with .NET using Visual Studio - -This tutorial shows how to automate unit testing by adding a test project to a solution. - -## Prerequisites - -This tutorial works with the solution that you create in [Create a .NET class library using Visual Studio](library-with-visual-studio.md). - -## Create a unit test project - -Unit tests provide automated software testing during your development and publishing. [MSTest](https://github.com/Microsoft/testfx-docs) is one of three test frameworks you can choose from. The others are [xUnit](https://xunit.net/) and [nUnit](https://nunit.org/). - -1. Start Visual Studio. - -1. Open the `ClassLibraryProjects` solution you created in [Create a .NET class library using Visual Studio](library-with-visual-studio.md). - -1. Add a new unit test project named "StringLibraryTest" to the solution. - - 1. Right-click on the solution in **Solution Explorer** and select **Add** > **New project**. - - 1. On the **Add a new project** page, enter **mstest** in the search box. Choose **C#** or **Visual Basic** from the Language list, and then choose **All platforms** from the Platform list. - - 1. Choose the **MSTest Test Project** template, and then choose **Next**. - - 1. On the **Configure your new project** page, enter **StringLibraryTest** in the **Project name** box. Then choose **Next**. - - 1. On the **Additional information** page, select **.NET 10** in the **Framework** box, select **Microsoft.Testing.Platform** for the **Test runner**, and then choose **Create**. - - :::image type="content" source="./media/testing-library-with-visual-studio/additional-information-mstest.png" alt-text="Enter additional information for the MSTest Test Project"::: - -1. Visual Studio creates the project and opens the class file in the code window with the following code. If the language you want to use isn't shown, change the language selector at the top of the page. - - ```csharp - namespace StringLibraryTest - { - - [TestClass] - public sealed class Test1 - { - [TestMethod] - public void TestMethod1() - { - } - } - } - ``` - - ```vb - Imports Microsoft.VisualStudio.TestTools.UnitTesting - - Namespace StringLibraryTest - - Public Class Test1 - - Sub TestSub() - - End Sub - End Class - End Namespace - ``` - - The source code created by the unit test template does the following: - - - Includes in the StringLibraryTest project file in C#, and imports in Visual Basic. - - Applies the attribute to the `Test1` class. - - Applies the attribute to define `TestMethod1` in C# or `TestSub` in Visual Basic. - - Each method tagged with [[TestMethod]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) in a test class tagged with [[TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) executes automatically when the unit test runs. - -## Add a project reference - -For the test project to work with the `StringLibrary` class, add a reference in the **StringLibraryTest** project to the `StringLibrary` project. Adding a reference to the `StringLibrary` assembly lets the compiler find **StringLibrary** methods while compiling the **StringLibraryTest** project. - -1. In **Solution Explorer**, right-click the **Dependencies** node of the **StringLibraryTest** project and select **Add Project Reference** from the context menu. - -1. In the **Reference Manager** dialog, select the box next to **StringLibrary**. - - :::image type="content" source="./media/testing-library-with-visual-studio/add-project-reference-string-library-test.png" alt-text="Add StringLibrary as a project reference for StringLibraryTest."::: - -1. Select **OK**. - -## Add and run unit test methods - -When Visual Studio runs a unit test, it executes each method marked with the attribute in a class marked with the attribute. A test method ends when the first failure is found or when all tests contained in the method succeed. - -The most common tests call members of the class. Many assert methods include at least two parameters, one of which is the expected test result and the other of which is the actual test result. Some of the `Assert` class's most frequently called methods are shown in the following table: - -| Assert methods | Function | -| ------------------ | -------- | -| `Assert.AreEqual` | Verifies that two values or objects are equal. The assert fails if the values or objects aren't equal. | -| `Assert.AreSame` | Verifies that two object variables refer to the same object. The assert fails if the variables refer to different objects. | -| `Assert.IsFalse` | Verifies that a condition is `false`. The assert fails if the condition is `true`. | -| `Assert.IsNotNull` | Verifies that an object isn't `null`. The assert fails if the object is `null`. | - -You can also use the (or `Assert.Throws` and `Assert.ThrowsExactly` if using MSTest 3.8 and later) method in a test method to indicate the type of exception it's expected to throw. The test fails if the specified exception isn't thrown. - -In testing the `StringLibrary.StartsWithUpper` method, you want to provide many strings that begin with an uppercase character. You expect the method to return `true` in these cases, so you can call the method. Similarly, you want to provide many strings that begin with something other than an uppercase character. You expect the method to return `false` in these cases, so you can call the method. - -Since your library method handles strings, you also want to make sure that it successfully handles an [empty string (`String.Empty`)](xref:System.String.Empty), a valid string that has no characters and whose is 0, and a `null` string that hasn't been initialized. Call `StartsWithUpper` directly as a static method and pass a single argument. Or call `StartsWithUpper` as an extension method on a `string` variable assigned to `null`. - -Define three methods, each of which calls an method for each element in a string array. Call a method overload that lets you specify an error message to be displayed in case of test failure. The message identifies the string that caused the failure. - -To create the test methods: - -1. In the *Test1.cs* or *Test1.vb* code window, replace the code with the following code: - - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibraryTest/Test1.cs"::: - :::code language="vb" source="./snippets/library-with-visual-studio/vb/StringLibraryTest/UnitTest1.vb"::: - - The test of uppercase characters in the `TestStartsWithUpper` method includes the Greek capital letter alpha (U+0391) and the Cyrillic capital letter EM (U+041C). The test of lowercase characters in the `TestDoesNotStartWithUpper` method includes the Greek small letter alpha (U+03B1) and the Cyrillic small letter Ghe (U+0433). - -1. On the menu bar, select **File** > **Save Test1.cs As** or **File** > **Save Test1.vb As**. In the **Save File As** dialog, select the arrow beside the **Save** button, and select **Save with Encoding**. - -1. In the **Confirm Save As** dialog, select the **Yes** button to save the file. - -1. In the **Advanced Save Options** dialog, select **Unicode (UTF-8 with signature) - Codepage 65001** from the **Encoding** drop-down list and select **OK**. - - If you fail to save your source code as a UTF8-encoded file, Visual Studio might save it as an ASCII file. When that happens, the runtime doesn't accurately decode the UTF8 characters outside of the ASCII range, and the test results aren't correct. - -1. On the menu bar, select **Test** > **Run All Tests**. If the **Test Explorer** window doesn't open, open it by choosing **Test** > **Test Explorer**. The three tests are listed in the **Passed Tests** section, and the **Summary** section reports the result of the test run. - - :::image type="content" source="./media/testing-library-with-visual-studio/test-explorer-window.png" alt-text="Test Explorer window with passing tests"::: - -## Handle test failures - -If you're doing test-driven development (TDD), you write tests first and they fail the first time you run them. Then you add code to the app that makes the test succeed. For this tutorial, you created the test after writing the app code that it validates, so you haven't seen the test fail. To validate that a test fails when you expect it to fail, add an invalid value to the test input. - -1. Modify the `words` array in the `TestDoesNotStartWithUpper` method to include the string "Error". You don't need to save the file because Visual Studio automatically saves open files when a solution is built to run tests. - - ```csharp - string[] words = { "alphabet", "Error", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство", - "1234", ".", ";", " " }; - ``` - - ```vb - Dim words() As String = { "alphabet", "Error", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство", - "1234", ".", ";", " " } - - ``` - -1. Run the test by selecting **Test** > **Run All Tests** from the menu bar. The **Test Explorer** window indicates that two tests succeeded and one failed. - - :::image type="content" source="./media/testing-library-with-visual-studio/failed-test-window.png" alt-text="Test Explorer window with failing tests"::: - -1. Select the failed test, `TestDoesNotStartWith`. - - The **Test Explorer** window displays the message produced by the assert: "Assert.IsFalse failed. Expected for 'Error': false; actual: True." Because of the failure, the strings in the array after "Error" weren't tested. - - :::image type="content" source="./media/testing-library-with-visual-studio/failed-test-detail.png" alt-text="Test Explorer window showing the IsFalse assertion failure"::: - -1. Remove the string "Error" that you added in step 1. Rerun the test and the tests pass. - -## Test the Release version of the library - -Now that the tests have all passed when running the Debug build of the library, run the tests another time against the Release build of the library. Some factors, including compiler optimizations, can sometimes produce different behavior between Debug and Release builds. - -To test the Release build: - -1. In the Visual Studio toolbar, change the build configuration from **Debug** to **Release**. - -1. In **Solution Explorer**, right-click the **StringLibrary** project and select **Build** from the context menu to recompile the library. - -1. Run the unit tests by choosing **Test** > **Run All Tests** from the menu bar. The tests pass. - -## Debug tests - -If you're using Visual Studio as your IDE, you can use the same process shown in [Tutorial: Debug a .NET console application using Visual Studio](debugging-with-visual-studio.md) to debug code using your unit test project. Instead of starting the *ShowCase* app project, right-click the **StringLibraryTests** project, and select **Debug Tests** from the context menu. - -Visual Studio starts the test project with the debugger attached. Execution stops at any breakpoint you've added to the test project or the underlying library code. - -## Additional resources - -- [Unit test basics - Visual Studio](/visualstudio/test/unit-test-basics) -- [Unit testing in .NET](../testing/index.md) - -## Next steps - -In this tutorial, you unit tested a class library. Make the library available to others by publishing it to [NuGet](https://nuget.org) as a package. To learn how, follow a NuGet tutorial: - -> [!div class="nextstepaction"] -> [Create and publish a NuGet package using Visual Studio](/nuget/quickstart/create-and-publish-a-package-using-visual-studio?tabs=netcore-cli) - -If you publish a library as a NuGet package, others can install and use it. To learn how, follow a NuGet tutorial: - -> [!div class="nextstepaction"] -> [Install and use a package in Visual Studio](/nuget/quickstart/install-and-use-a-package-in-visual-studio) - -A library doesn't have to be distributed as a package. It can be bundled with a console app that uses it. To learn how to publish a console app, see the earlier tutorial in this series: - -> [!div class="nextstepaction"] -> [Publish a .NET console application using Visual Studio](publishing-with-visual-studio.md) diff --git a/docs/core/tutorials/testing-with-cli.md b/docs/core/tutorials/testing-with-cli.md index e1c8c8624bcdd..e2ea04e319e3e 100644 --- a/docs/core/tutorials/testing-with-cli.md +++ b/docs/core/tutorials/testing-with-cli.md @@ -7,7 +7,7 @@ ai-usage: ai-assisted # Organizing and testing projects with the .NET CLI -This tutorial follows [Tutorial: Create a console application with .NET using Visual Studio Code](with-visual-studio-code.md), taking you beyond the creation of a simple console app to develop advanced and well-organized applications. After showing you how to use folders to organize your code, the tutorial shows you how to extend a console application with the [xUnit](https://xunit.net/) testing framework. +This tutorial follows [Tutorial: Create a .NET console application](create-console-app.md), taking you beyond the creation of a simple console app to develop advanced and well-organized applications. After showing you how to use folders to organize your code, the tutorial shows you how to extend a console application with the [xUnit](https://xunit.net/) testing framework. > [!NOTE] > This tutorial recommends that you place the application project and test project in separate folders. Some developers prefer to keep these projects in the same folder. For more information, see GitHub issue [dotnet/docs #26395](https://github.com/dotnet/docs/issues/26395). diff --git a/docs/core/tutorials/with-visual-studio.md b/docs/core/tutorials/with-visual-studio.md deleted file mode 100644 index 0490eb7d67f97..0000000000000 --- a/docs/core/tutorials/with-visual-studio.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: Create a .NET console application using Visual Studio -description: Learn how to create a .NET console application with C# or Visual Basic using Visual Studio. -ms.date: 01/13/2026 -dev_langs: - - "csharp" - - "vb" -ms.custom: vs-dotnet ---- -# Tutorial: Create a .NET console application using Visual Studio - -This tutorial shows how to create and run a .NET console application in Visual Studio 2026. - -## Prerequisites - -- [Visual Studio 2026 or later](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=learn.microsoft.com&utm_campaign=inline+link) with the **.NET desktop development** workload installed. The .NET SDK is automatically installed when you select this workload. - - For more information, see [Install the .NET SDK with Visual Studio](../install/windows.md#install-with-visual-studio). - -## Create the app - -Create a .NET console app project named "HelloWorld". - -1. Start Visual Studio. - -1. On the start page, choose **Create a new project**. - - :::image type="content" source="./media/with-visual-studio/start-window.png" alt-text="Create a new project button selected on the Visual Studio start page"::: - -1. On the **Create a new project** page, enter **console** in the search box. Next, choose **C#** or **Visual Basic** from the language list, and then choose **All platforms** from the platform list. Choose the **Console App** template, and then choose **Next**. - - :::image type="content" source="./media/with-visual-studio/create-new-project.png" alt-text="Create a new project window with filters selected"::: - - > [!TIP] - > If you don't see the .NET templates, you're probably missing the required workload. Under the **Not finding what you're looking for?** message, choose the **Install more tools and features** link. The Visual Studio Installer opens. Make sure you have the **.NET desktop development** workload installed. - -1. In the **Configure your new project** dialog, enter **HelloWorld** in the **Project name** box. Then choose **Next**. - - :::image type="content" source="./media/with-visual-studio/configure-new-project.png" alt-text="Configure your new project window with Project name, location, and solution name fields"::: - -1. In the **Additional information** dialog: - - Select **.NET 10.0 (Long Term Support)**. - - Select **Create**. - - :::image type="content" source="./media/with-visual-studio/additional-information.png" alt-text="Enter additional information for the console app."::: - - The template creates a simple application that displays "Hello, World!" in the console window. The code is in the *Program.cs* or *Program.vb* file: - - ```csharp - // See https://aka.ms/new-console-template for more information - Console.WriteLine("Hello, World!"); - ``` - - ```vb - Imports System - - Module Program - Sub Main(args As String()) - Console.WriteLine("Hello World!") - End Sub - End Module - ``` - - If the language you want to use is not shown, change the language selector at the top of the page. - - The C# template uses top-level statements to call the method to display a message in the console window. The Visual Basic template defines a `Module Program` with a `Sub Main` method that calls the same method. - -## Run the app - -1. Press Ctrl+F5 to run the program without debugging. - - A console window opens with the text "Hello, World!" printed on the screen. (Or "Hello World!" without a comma in the Visual Basic project template.) - -1. Press any key to close the console window. - -## Enhance the app - -Enhance the application to prompt the user for their name and display it along with the date and time. - -1. In *Program.cs* or *Program.vb*, replace the contents with the following code: - - :::code language="csharp" source="./snippets/with-visual-studio/csharp/Program.cs" id="MainMethod"::: - :::code language="vb" source="./snippets/with-visual-studio/vb/Program.vb" id="MainMethod"::: - - This code displays a prompt in the console window and waits until the user enters a string followed by the Enter key. It stores this string in a variable named `name`. It also retrieves the value of the property, which contains the current local time, and assigns it to a variable named `currentDate`. And it displays these values in the console window. Finally, it displays a prompt in the console window and calls the method to wait for user input. - - is a platform-independent and language-independent way to represent a line break. Alternatives are `\n` in C# and `vbCrLf` in Visual Basic. - - The dollar sign (`$`) in front of a string lets you put expressions such as variable names in curly braces in the string. The expression value is inserted into the string in place of the expression. This syntax is referred to as [interpolated strings](../../csharp/language-reference/tokens/interpolated.md). - -1. Press Ctrl+F5 to run the program without debugging. - -1. Respond to the prompt by entering a name and pressing the Enter key. - - :::image type="content" source="./media/with-visual-studio/hello-world-update.png" alt-text="Console window with modified program output"::: - -1. Press any key to close the console window. - -## Additional resources - -- [Standard-term support (STS) releases and long-term support (LTS) releases](../releases-and-support.md#release-tracks). - -## Next steps - -In this tutorial, you created a .NET console application. In the next tutorial, you debug the app. - -> [!div class="nextstepaction"] -> [Debug a .NET console application using Visual Studio](debugging-with-visual-studio.md) diff --git a/docs/csharp/fundamentals/program-structure/main-command-line.md b/docs/csharp/fundamentals/program-structure/main-command-line.md index 08e82eaa09cd5..a4c6c2400cf64 100644 --- a/docs/csharp/fundamentals/program-structure/main-command-line.md +++ b/docs/csharp/fundamentals/program-structure/main-command-line.md @@ -78,7 +78,7 @@ However, returning `int` or `Task` enables the program to communicate statu The following example shows how the exit code for the process can be accessed. -This example uses [.NET Core](../../../core/introduction.md) command-line tools. If you're unfamiliar with .NET Core command-line tools, you can learn about them in this [get-started article](../../../core/tutorials/with-visual-studio-code.md). +This example uses [.NET Core](../../../core/introduction.md) command-line tools. If you're unfamiliar with .NET Core command-line tools, you can learn about them in this [get-started article](../../../core/tutorials/create-console-app.md). Create a new application by running `dotnet new console`. Modify the `Main` method in *Program.cs* as follows: diff --git a/docs/fundamentals/index.yml b/docs/fundamentals/index.yml index 82fe8517df101..bd92ebcbee989 100644 --- a/docs/fundamentals/index.yml +++ b/docs/fundamentals/index.yml @@ -89,10 +89,8 @@ landingContent: url: https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro - linkListType: tutorial links: - - text: Create a Hello World app in Visual Studio Code - url: ../core/tutorials/with-visual-studio-code.md - - text: Create a Hello World app in Visual Studio - url: ../core/tutorials/with-visual-studio.md + - text: Create a Hello World app + url: ../core/tutorials/create-console-app.md - text: Containerize a .NET Core app url: ../core/docker/build-container.md - linkListType: concept diff --git a/docs/fundamentals/toc.yml b/docs/fundamentals/toc.yml index 560e9b27fc79b..d10db20899e78 100644 --- a/docs/fundamentals/toc.yml +++ b/docs/fundamentals/toc.yml @@ -95,54 +95,29 @@ items: href: ../standard/glossary.md - name: Tutorials items: + - name: Create a console app + href: ../core/tutorials/create-console-app.md + displayName: tutorials, visual studio, vs, visual studio code, vs code + - name: Debug an app + href: ../core/tutorials/debug-console-app.md + displayName: tutorials, visual studio, vs, visual studio code, vs code + - name: Publish an app + href: ../core/tutorials/publish-console-app.md + displayName: tutorials, visual studio, vs, visual studio code, vs code + - name: Create a library + href: ../core/tutorials/create-class-library.md + displayName: tutorials, visual studio, vs, visual studio code, vs code + - name: Unit test a library + href: ../core/tutorials/test-class-library.md + displayName: tutorials, visual studio, vs, visual studio code, vs code + - name: Install and use a package + href: /nuget/quickstart/install-and-use-a-package-using-the-dotnet-cli?toc=/dotnet/fundamentals/toc.json&bc=/dotnet/breadcrumb/toc.json + displayName: tutorials, cli + - name: Create and publish a package + href: /nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli?toc=/dotnet/fundamentals/toc.json&bc=/dotnet/breadcrumb/toc.json + displayName: tutorials, cli - name: .NET 6 template changes href: ../core/tutorials/top-level-templates.md - - name: Use Visual Studio - items: - - name: Create a console app - href: ../core/tutorials/with-visual-studio.md - displayName: tutorials, visual studio, vs - - name: Debug an app - href: ../core/tutorials/debugging-with-visual-studio.md - displayName: tutorials, visual studio, vs - - name: Publish an app - href: ../core/tutorials/publishing-with-visual-studio.md - displayName: tutorials, visual studio, vs - - name: Create a library - href: ../core/tutorials/library-with-visual-studio.md - displayName: tutorials, visual studio, vs - - name: Unit test a library - href: ../core/tutorials/testing-library-with-visual-studio.md - displayName: tutorials, visual studio, vs - - name: Install and use a package - href: /nuget/quickstart/install-and-use-a-package-in-visual-studio?toc=/dotnet/fundamentals/toc.json&bc=/dotnet/breadcrumb/toc.json - displayName: tutorials, visual studio, vs - - name: Create and publish a package - href: /nuget/quickstart/create-and-publish-a-package-using-visual-studio?toc=/dotnet/fundamentals/toc.json&bc=/dotnet/breadcrumb/toc.json - displayName: tutorials, visual studio, vs - - name: Use Visual Studio Code - items: - - name: Create a console app - href: ../core/tutorials/with-visual-studio-code.md - displayName: tutorials, visual studio code, vs code, cli - - name: Debug an app - href: ../core/tutorials/debugging-with-visual-studio-code.md - displayName: tutorials, visual studio code, vs code - - name: Publish an app - href: ../core/tutorials/publishing-with-visual-studio-code.md - displayName: tutorials, visual studio code, vs code - - name: Create a library - href: ../core/tutorials/library-with-visual-studio-code.md - displayName: tutorials, visual studio code, vs code - - name: Unit test a library - href: ../core/tutorials/testing-library-with-visual-studio-code.md - displayName: tutorials, visual studio code, vs code - - name: Install and use a package - href: /nuget/quickstart/install-and-use-a-package-using-the-dotnet-cli?toc=/dotnet/fundamentals/toc.json&bc=/dotnet/breadcrumb/toc.json - displayName: tutorials, cli - - name: Create and publish a package - href: /nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli?toc=/dotnet/fundamentals/toc.json&bc=/dotnet/breadcrumb/toc.json - displayName: tutorials - name: More tutorials href: ../core/tutorials/index.md - name: What's new in .NET diff --git a/docs/iot/tutorials/adc.md b/docs/iot/tutorials/adc.md index 9d9cbb20dab82..ddc8869af7fbb 100644 --- a/docs/iot/tutorials/adc.md +++ b/docs/iot/tutorials/adc.md @@ -60,7 +60,7 @@ Refer to the following pinout diagrams as needed: Complete the following steps in your preferred development environment: -1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/with-visual-studio.md). Name it *AdcTutorial*. +1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/create-console-app.md). Name it *AdcTutorial*. ```dotnetcli dotnet new console -o AdcTutorial diff --git a/docs/iot/tutorials/blink-led.md b/docs/iot/tutorials/blink-led.md index d35cb15c66099..cee5b7249f06f 100644 --- a/docs/iot/tutorials/blink-led.md +++ b/docs/iot/tutorials/blink-led.md @@ -46,7 +46,7 @@ The image above depicts the following connections: Complete the following steps in your preferred development environment: -1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/with-visual-studio.md). Name it *BlinkTutorial*. +1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/create-console-app.md). Name it *BlinkTutorial*. ```dotnetcli dotnet new console -o BlinkTutorial diff --git a/docs/iot/tutorials/gpio-input.md b/docs/iot/tutorials/gpio-input.md index 76720e5236698..a716c1d20230a 100644 --- a/docs/iot/tutorials/gpio-input.md +++ b/docs/iot/tutorials/gpio-input.md @@ -43,7 +43,7 @@ The image above depicts a direct connection between a ground pin and pin 21. Complete the following steps in your preferred development environment: -1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/with-visual-studio.md). Name it *InputTutorial*. +1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/create-console-app.md). Name it *InputTutorial*. ```dotnetcli dotnet new console -o InputTutorial diff --git a/docs/iot/tutorials/lcd-display.md b/docs/iot/tutorials/lcd-display.md index 0ab2db9cf2434..212b45dd859e3 100644 --- a/docs/iot/tutorials/lcd-display.md +++ b/docs/iot/tutorials/lcd-display.md @@ -53,7 +53,7 @@ Refer to the following figures as needed: Complete the following steps in your preferred development environment: -1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/with-visual-studio.md). Name it *LcdTutorial*. +1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/create-console-app.md). Name it *LcdTutorial*. ```dotnetcli dotnet new console -o LcdTutorial diff --git a/docs/iot/tutorials/temp-sensor.md b/docs/iot/tutorials/temp-sensor.md index 1faf7f539cb2a..61c64ab55d948 100644 --- a/docs/iot/tutorials/temp-sensor.md +++ b/docs/iot/tutorials/temp-sensor.md @@ -55,7 +55,7 @@ The following are the connections from the Raspberry Pi to the BME280 breakout. Complete the following steps in your preferred development environment: -1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/with-visual-studio.md). Name it *SensorTutorial*. +1. Create a new .NET Console App using either the [.NET CLI](../../core/tools/dotnet-new.md) or [Visual Studio](../../core/tutorials/create-console-app.md). Name it *SensorTutorial*. ```dotnetcli dotnet new console -o SensorTutorial diff --git a/docs/orleans/tutorials-and-samples/tutorial-1.md b/docs/orleans/tutorials-and-samples/tutorial-1.md index cc962bf77f685..a00588837b8ac 100644 --- a/docs/orleans/tutorials-and-samples/tutorial-1.md +++ b/docs/orleans/tutorials-and-samples/tutorial-1.md @@ -54,9 +54,9 @@ For this tutorial, create four projects as part of the same solution: Replace the default code with the code provided for each project. -1. Start by creating a Console App project in a new solution. Call the project `Silo` and name the solution `OrleansHelloWorld`. For more information on creating a console app, see [Tutorial: Create a .NET console application using Visual Studio](../../core/tutorials/with-visual-studio.md). +1. Start by creating a Console App project in a new solution. Call the project `Silo` and name the solution `OrleansHelloWorld`. For more information on creating a console app, see [Tutorial: Create a .NET console application](../../core/tutorials/create-console-app.md). 1. Add another Console App project and name it `Client`. -1. Add a Class Library and name it `GrainInterfaces`. For information on creating a class library, see [Tutorial: Create a .NET class library using Visual Studio](../../core/tutorials/library-with-visual-studio.md). +1. Add a Class Library and name it `GrainInterfaces`. For information on creating a class library, see [Tutorial: Create a .NET class library](../../core/tutorials/create-class-library.md). 1. Add another Class Library and name it `Grains`. #### Delete default source files diff --git a/docs/samples-and-tutorials/index.md b/docs/samples-and-tutorials/index.md index c19e38e29a57d..e793e563fe556 100644 --- a/docs/samples-and-tutorials/index.md +++ b/docs/samples-and-tutorials/index.md @@ -20,13 +20,13 @@ This guide shows you how to create an ASP.NET Core web app and associated unit t ### Tutorials -**[Tutorial: Create a .NET console application using Visual Studio Code](../core/tutorials/with-visual-studio-code.md)** +**[Tutorial: Create a .NET console application](../core/tutorials/create-console-app.md)** -This tutorial shows how to create and run a .NET console application by using Visual Studio Code and the .NET CLI. Project tasks, such as creating, compiling, and running a project are done by using the .NET CLI. +This tutorial shows how to create and run a .NET console application using Visual Studio, Visual Studio Code, or GitHub Codespaces. -**[Tutorial: Create a .NET class library using Visual Studio Code](../core/tutorials/library-with-visual-studio-code.md)** +**[Tutorial: Create a .NET class library](../core/tutorials/create-class-library.md)** -This tutorial shows how to write libraries for .NET using Visual Studio Code and the .NET CLI. Project tasks, such as creating, compiling, and running a project are done by using the .NET CLI. +This tutorial shows how to create a class library using Visual Studio, Visual Studio Code, or GitHub Codespaces. For more .NET tutorials, see [Learn .NET and the .NET SDK tools](../core/tutorials/index.md). diff --git a/docs/standard/get-started.md b/docs/standard/get-started.md index b0d9e06008d6d..3d59414e27a19 100644 --- a/docs/standard/get-started.md +++ b/docs/standard/get-started.md @@ -1,7 +1,7 @@ --- title: Tutorials for getting started with .NET description: Choose a tutorial for learning .NET app development or one of the .NET programming languages. -ms.date: 09/30/2020 +ms.date: 02/12/2026 --- # Tutorials for getting started with .NET @@ -9,9 +9,7 @@ The following step-by-step tutorials run on Windows, Linux, or macOS, except as ## Tutorials for creating apps -* Create a console app - * [using Visual Studio Code](../core/tutorials/with-visual-studio-code.md) - * [using Visual Studio](../core/tutorials/with-visual-studio.md) (Windows) +* [Create a console app](../core/tutorials/create-console-app.md) * Create a web app * [with server-side web UI](/aspnet/core/tutorials/razor-pages/razor-pages-start) * [with client-side web UI](https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro) @@ -29,9 +27,7 @@ The following step-by-step tutorials run on Windows, Linux, or macOS, except as ## Tutorials for creating class libraries -* Create a class library - * [using Visual Studio Code](../core/tutorials/library-with-visual-studio-code.md) - * [using Visual Studio](../core/tutorials/library-with-visual-studio.md) (Windows) +* [Create a class library](../core/tutorials/create-class-library.md) ## Resources for learning .NET languages diff --git a/docs/standard/net-standard.md b/docs/standard/net-standard.md index e62e77cc94541..682f6098c96a9 100644 --- a/docs/standard/net-standard.md +++ b/docs/standard/net-standard.md @@ -149,5 +149,5 @@ Here are some problems with .NET Standard that help explain why .NET 5 and later - [.NET Standard versions (source)](https://github.com/dotnet/standard/blob/v2.1.0/docs/versions.md) - [.NET Standard versions (interactive UI)](https://dotnet.microsoft.com/platform/dotnet-standard#versions) -- [Build a .NET Standard library](../core/tutorials/library-with-visual-studio.md) +- [Build a .NET Standard library](../core/tutorials/create-class-library.md) - [Cross-platform targeting](./library-guidance/cross-platform-targeting.md) diff --git a/docs/visual-basic/getting-started/index.md b/docs/visual-basic/getting-started/index.md index c0ca39e38b0f7..813a2a855259d 100644 --- a/docs/visual-basic/getting-started/index.md +++ b/docs/visual-basic/getting-started/index.md @@ -13,9 +13,9 @@ This section of the documentation helps you get started with Visual Basic applic ## Get started with Visual Basic and .NET Core -[Build a Hello World application with .NET Core in Visual Studio](../../core/tutorials/with-visual-studio.md) +[Build a Hello World application with .NET](../../core/tutorials/create-console-app.md) -[Build a class library with .NET Standard in Visual Studio](../../core/tutorials/library-with-visual-studio.md) +[Build a class library with .NET](../../core/tutorials/create-class-library.md) ## Additional information diff --git a/docs/zone-pivot-groups.yml b/docs/zone-pivot-groups.yml index 41cf8432c85d1..2f6c9a515c9bd 100644 --- a/docs/zone-pivot-groups.yml +++ b/docs/zone-pivot-groups.yml @@ -164,6 +164,8 @@ groups: title: Code editor prompt: Choose a code editor pivots: + - id: visualstudio + title: Visual Studio - id: vscode title: Visual Studio Code - id: codespaces