diff --git a/docs/core/tutorials/debugging-with-visual-studio-code.md b/docs/core/tutorials/debugging-with-visual-studio-code.md index f9e0cd5a34e1f..3abe51018cdf9 100644 --- a/docs/core/tutorials/debugging-with-visual-studio-code.md +++ b/docs/core/tutorials/debugging-with-visual-studio-code.md @@ -1,13 +1,13 @@ --- title: Debug a .NET console application using Visual Studio Code description: Learn how to debug a .NET console app using Visual Studio Code. -ms.date: 10/22/2021 +ms.date: 11/11/2022 zone_pivot_groups: dotnet-version recommendations: false --- # Tutorial: Debug a .NET console application using Visual Studio Code -::: zone pivot="dotnet-7-0,dotnet-6-0" +::: zone pivot="dotnet-7-0" This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps. @@ -216,7 +216,7 @@ In this tutorial, you used Visual Studio Code debugging tools. In the next tutor ::: zone-end -::: zone pivot="dotnet-5-0" +::: zone pivot="dotnet-6-0" This tutorial introduces the debugging tools available in Visual Studio Code for working with .NET apps. @@ -226,7 +226,7 @@ This tutorial introduces the debugging tools available in Visual Studio Code for ## Use Debug build configuration -*Debug* and *Release* are .NET Core's built-in build configurations. You use the Debug build configuration for debugging and the Release configuration for the final release distribution. +*Debug* and *Release* are .NET's built-in build configurations. You use the Debug build configuration for debugging and the Release configuration for the final release distribution. In the Debug configuration, a program compiles with full symbolic debug information and no optimization. Optimization complicates debugging, because the relationship between source code and generated instructions is more complex. The release configuration of a program has no symbolic debug information and is fully optimized. @@ -238,7 +238,7 @@ By default, Visual Studio Code launch settings use the Debug build configuration ## Set a breakpoint -A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is executed. +A *breakpoint* temporarily interrupts the execution of the application before the line with the breakpoint is run. 1. Open the *Program.cs* file. @@ -246,7 +246,7 @@ A *breakpoint* temporarily interrupts the execution of the application before th Visual Studio Code indicates the line on which the breakpoint is set by displaying a red dot in the left margin. - :::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set.png" alt-text="Breakpoint set"::: + :::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-set-net6.png" alt-text="Breakpoint set"::: ## Set up for terminal input @@ -266,7 +266,7 @@ The breakpoint is located after a `Console.ReadLine` method call. The **Debug Co 1. Open the Debug view by selecting the Debugging icon on the left side menu. - :::image type="content" source="media/debugging-with-visual-studio-code/select-debug-pane.png" alt-text="Open the Debug tab in Visual Studio Code"::: + :::image type="content" source="media/debugging-with-visual-studio-code/select-debug-pane-net6.png" alt-text="Open the Debug tab in Visual Studio Code"::: 1. Select the green arrow at the top of the pane, next to **.NET Core Launch (console)**. Other ways to start the program in debugging mode are by pressing F5 or choosing **Run** > **Start Debugging** from the menu. @@ -274,13 +274,13 @@ The breakpoint is located after a `Console.ReadLine` method call. The **Debug Co 1. Select the **Terminal** tab to see the "What is your name?" prompt that the program displays before waiting for a response. - :::image type="content" source="media/debugging-with-visual-studio-code/select-terminal.png" alt-text="Select the Terminal tab"::: + :::image type="content" source="media/debugging-with-visual-studio-code/select-terminal-net6.png" alt-text="Select the Terminal tab"::: 1. Enter a string in the **Terminal** window in response to the prompt for a name, and then press Enter. - Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method executes. The **Locals** section of the **Variables** window displays the values of variables that are defined in the currently executing method. + Program execution stops when it reaches the breakpoint and before the `Console.WriteLine` method runs. The **Locals** section of the **Variables** window displays the values of variables that are defined in the currently running method. - :::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-hit.png" alt-text="Breakpoint hit, showing Locals"::: + :::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-hit-net6.png" alt-text="Breakpoint hit, showing Locals"::: ## Use the Debug Console @@ -290,7 +290,7 @@ The **Debug Console** window lets you interact with the application you're debug 1. Enter `name = "Gracie"` at the prompt at the bottom of the **Debug Console** window and press the Enter key. - :::image type="content" source="media/debugging-with-visual-studio-code/change-variable-values.png" alt-text="Change variable values"::: + :::image type="content" source="media/debugging-with-visual-studio-code/change-variable-values-net6.png" alt-text="Change variable values"::: 1. Enter `currentDate = DateTime.Parse("2019-11-16T17:25:00Z").ToUniversalTime()` at the bottom of the **Debug Console** window and press the Enter key. @@ -314,7 +314,7 @@ The program displays the string that the user enters. What happens if the user d 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"::: + :::image type="content" source="media/debugging-with-visual-studio-code/breakpoint-context-menu-net6.png" alt-text="Breakpoint context menu"::: 1. Select `Expression` in the drop-down, enter the following conditional expression, and press Enter. @@ -322,17 +322,17 @@ The program displays the string that the user enters. What happens if the user d String.IsNullOrEmpty(name) ``` - :::image type="content" source="media/debugging-with-visual-studio-code/conditional-expression.png" alt-text="Enter a conditional expression"::: + :::image type="content" source="media/debugging-with-visual-studio-code/conditional-expression-net6.png" alt-text="Enter a conditional expression"::: Each time the breakpoint is hit, the debugger calls the `String.IsNullOrEmpty(name)` method, and it breaks on this line only if the method call returns `true`. - Instead of a conditional expression, you can specify a *hit count*, which interrupts program execution before a statement is executed a specified number of times. Another option is to specify a *filter condition*, which interrupts program execution based on such attributes as a thread identifier, process name, or thread name. + Instead of a conditional expression, you can specify a *hit count*, which interrupts program execution before a statement is run a specified number of times. Another option is to specify a *filter condition*, which interrupts program execution based on such attributes as a thread identifier, process name, or thread name. 1. Start the program with debugging by pressing F5. 1. In the **Terminal** tab, press the Enter key 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 executes. + 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 . @@ -342,8 +342,6 @@ The program displays the string that the user enters. What happens if the user d name == String.Empty ``` - :::image type="content" source="media/debugging-with-visual-studio-code/expression-in-debug-console.png" alt-text="Debug Console returning a value of true after the statement is executed"::: - 1. Select the **Continue** button on the toolbar to continue program execution. 1. Select the **Terminal** tab, and press any key to exit the program and stop debugging. @@ -372,7 +370,7 @@ Visual Studio Code also allows you to step line by line through a program and mo 1. Select **Run** > **Step Into** or press F11. - Visual Studio Code executes the `Console.WriteLine` for the name prompt and highlights the next line of execution. The next line is the `Console.ReadLine` for the `name`. The **Variables** window is unchanged, and the **Terminal** tab shows the "What is your name?" prompt. + Visual Studio Code runs the `Console.WriteLine` for the name prompt and highlights the next line of execution. The next line is the `Console.ReadLine` for the `name`. The **Variables** window is unchanged, and the **Terminal** tab shows the "What is your name?" prompt. 1. Select **Run** > **Step Into** or press F11. @@ -427,8 +425,8 @@ In this tutorial, you used Visual Studio Code debugging tools. In the next tutor ::: zone-end -::: zone pivot="dotnet-core-3-1" +::: zone pivot="dotnet-core-3-1,dotnet-5-0" -This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page. +This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page. ::: zone-end diff --git a/docs/core/tutorials/library-with-visual-studio-code.md b/docs/core/tutorials/library-with-visual-studio-code.md index eb843159a6acc..532f9173ca799 100644 --- a/docs/core/tutorials/library-with-visual-studio-code.md +++ b/docs/core/tutorials/library-with-visual-studio-code.md @@ -1,24 +1,24 @@ --- title: Create a .NET class library using Visual Studio Code description: Learn how to create a .NET class library using Visual Studio Code. -ms.date: 10/25/2021 +ms.date: 11/11/2022 zone_pivot_groups: dotnet-version recommendations: false --- # Tutorial: Create a .NET class library using Visual Studio Code -::: zone pivot="dotnet-7-0,dotnet-6-0" +::: zone pivot="dotnet-7-0" In this tutorial, you create a simple utility library that contains a single string-handling method. -A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 6, it can be called by any application that targets .NET 6. This tutorial shows how to target .NET 6. +A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 7, it can be called by any application that targets .NET 7. This tutorial shows how to target .NET 7. When you create a class library, you can distribute it as a third-party component or as a bundled component with one or more applications. ## Prerequisites * [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery). -* The [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0). +* The [.NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0). ## Create a solution @@ -81,15 +81,15 @@ Add a new .NET class library project named "StringLibrary" to the solution. Project `StringLibrary\StringLibrary.csproj` added to the solution. ``` -1. Check to make sure that the library targets .NET 6. In **Explorer**, open *StringLibrary/StringLibrary.csproj*. +1. Check to make sure that the library targets .NET 7. In **Explorer**, open *StringLibrary/StringLibrary.csproj*. - The `TargetFramework` element shows that the project targets .NET 6.0. + The `TargetFramework` element shows that the project targets .NET 7.0. ```xml - net6.0 + net7.0 @@ -114,11 +114,11 @@ Add a new .NET class library project named "StringLibrary" to the solution. The terminal output looks like the following example: ```output - Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET + Microsoft (R) Build Engine version 16.7.4+b89cb5fde for .NET Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... All projects are up-to-date for restore. - StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net6.0\StringLibrary.dll + StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net7.0\StringLibrary.dll Build succeeded. 0 Warning(s) 0 Error(s) @@ -222,18 +222,18 @@ In this tutorial, you created a solution, added a library project, and added a c ::: zone-end -::: zone pivot="dotnet-5-0" +::: zone pivot="dotnet-6-0" In this tutorial, you create a simple utility library that contains a single string-handling method. -A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 5, it can be called by any application that targets .NET 5. This tutorial shows how to target .NET 5. +A *class library* defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 6, it can be called by any application that targets .NET 6. This tutorial shows how to target .NET 6. When you create a class library, you can distribute it as a third-party component or as a bundled component with one or more applications. ## Prerequisites -1. [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery). -2. The [.NET 5.0 SDK or later](https://dotnet.microsoft.com/download) +* [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery). +* The [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0). ## Create a solution @@ -296,15 +296,15 @@ Add a new .NET class library project named "StringLibrary" to the solution. Project `StringLibrary\StringLibrary.csproj` added to the solution. ``` -1. Check to make sure that the library targets .NET 5. In **Explorer**, open *StringLibrary/StringLibrary.csproj*. +1. Check to make sure that the library targets .NET 6. In **Explorer**, open *StringLibrary/StringLibrary.csproj*. - The `TargetFramework` element shows that the project targets .NET 5.0. + The `TargetFramework` element shows that the project targets .NET 6.0. ```xml - net5.0 + net6.0 @@ -312,11 +312,11 @@ Add a new .NET class library project named "StringLibrary" to the solution. 1. Open *Class1.cs* and replace the code with the following code. - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs"::: + :::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/StringLibrary/Class1.cs"::: The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a 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` indicates that the string may be null. + `StartsWithUpper` is implemented as an [extension method](../../csharp/programming-guide/classes-and-structs/extension-methods.md) so that you can call it as if it were a member of the class. 1. Save the file. @@ -333,7 +333,7 @@ Add a new .NET class library project named "StringLibrary" to the solution. Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... All projects are up-to-date for restore. - StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net5.0\StringLibrary.dll + StringLibrary -> C:\Projects\ClassLibraryProjects\StringLibrary\bin\Debug\net6.0\StringLibrary.dll Build succeeded. 0 Warning(s) 0 Error(s) @@ -375,7 +375,7 @@ Add a console application that uses the class library. The app will prompt the u 1. Open *ShowCase/Program.cs* and replace all of the code with the following code. - :::code language="csharp" source="./snippets/library-with-visual-studio/csharp/ShowCase/Program.cs"::: + :::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/ShowCase/Program.cs"::: The code uses the `row` variable to maintain a count of the number of rows of data written to the console window. Whenever it's greater than or equal to 25, the code clears the console window and displays a message to the user. @@ -437,8 +437,8 @@ In this tutorial, you created a solution, added a library project, and added a c ::: zone-end -::: zone pivot="dotnet-core-3-1" +::: zone pivot="dotnet-core-3-1,dotnet-5-0" -This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page. +This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page. ::: zone-end diff --git a/docs/core/tutorials/media/publishing-with-visual-studio-code/published-files-output-net7.png b/docs/core/tutorials/media/publishing-with-visual-studio-code/published-files-output-net7.png new file mode 100644 index 0000000000000..c53081a1b5516 Binary files /dev/null and b/docs/core/tutorials/media/publishing-with-visual-studio-code/published-files-output-net7.png differ diff --git a/docs/core/tutorials/publishing-with-visual-studio-code.md b/docs/core/tutorials/publishing-with-visual-studio-code.md index f9d93eb712b65..9109c37388ed3 100644 --- a/docs/core/tutorials/publishing-with-visual-studio-code.md +++ b/docs/core/tutorials/publishing-with-visual-studio-code.md @@ -1,13 +1,13 @@ --- 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: 10/22/2021 +ms.date: 11/11/2022 zone_pivot_groups: dotnet-version recommendations: false --- # Tutorial: Publish a .NET console application using Visual Studio Code -::: zone pivot="dotnet-7-0,dotnet-6-0" +::: zone pivot="dotnet-7-0" 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. @@ -38,12 +38,12 @@ The .NET CLI is used to publish the app, so you can follow this tutorial with a The command output is similar to the following example: ```output - Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET + Microsoft (R) Build Engine version 16.7.4+b89cb5fde for .NET Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... All projects are up-to-date for restore. - HelloWorld -> C:\Projects\HelloWorld\bin\Release\net6.0\HelloWorld.dll - HelloWorld -> C:\Projects\HelloWorld\bin\Release\net6.0\publish\ + HelloWorld -> C:\Projects\HelloWorld\bin\Release\net7.0\HelloWorld.dll + HelloWorld -> C:\Projects\HelloWorld\bin\Release\net7.0\publish\ ``` ## Inspect the files @@ -54,9 +54,9 @@ In the following steps, you'll look at the files created by the publish process. 1. Select the **Explorer** in the left navigation bar. -1. Expand *bin/Release/net6.0/publish*. +1. Expand *bin/Release/net7.0/publish*. - :::image type="content" source="media/publishing-with-visual-studio-code/published-files-output-net6.png" alt-text="Explorer showing published files"::: + :::image type="content" source="media/publishing-with-visual-studio-code/published-files-output-net7.png" alt-text="Explorer showing published files"::: As the image shows, the published output includes the following files: @@ -113,7 +113,7 @@ In this tutorial, you published a console app. In the next tutorial, you create ::: zone-end -::: zone pivot="dotnet-5-0" +::: zone pivot="dotnet-6-0" 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. @@ -148,8 +148,8 @@ The .NET CLI is used to publish the app, so you can follow this tutorial with a Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... All projects are up-to-date for restore. - HelloWorld -> C:\Projects\HelloWorld\bin\Release\net5.0\HelloWorld.dll - HelloWorld -> C:\Projects\HelloWorld\bin\Release\net5.0\publish\ + HelloWorld -> C:\Projects\HelloWorld\bin\Release\net6.0\HelloWorld.dll + HelloWorld -> C:\Projects\HelloWorld\bin\Release\net6.0\publish\ ``` ## Inspect the files @@ -160,19 +160,19 @@ In the following steps, you'll look at the files created by the publish process. 1. Select the **Explorer** in the left navigation bar. -1. Expand *bin/Release/net5.0/publish*. +1. Expand *bin/Release/net6.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/publishing-with-visual-studio-code/published-files-output-net6.png" alt-text="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). + 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/4af56f867f2f638b4562c3b8432d70f7b09577b3/Documentation/specs/runtime-configuration-file.md). * *HelloWorld.dll* - This is the [framework-dependent deployment](../deploying/deploy-with-cli.md#framework-dependent-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. + This is the [framework-dependent deployment](../deploying/deploy-with-cli.md#framework-dependent-deployment) version of the application. To run 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* (*HelloWorld* on Linux, not created on macOS.) @@ -188,7 +188,7 @@ In the following steps, you'll look at the files created by the publish process. ## Run the published app -1. In **Explorer**, right-click the *publish* folder (Ctrl-click on macOS), and select **Open in Integrated Terminal**. +1. In **Explorer**, right-click the *publish* folder (Ctrl-click on macOS), and select **Open in Terminal**. :::image type="content" source="media/publishing-with-visual-studio-code/open-in-terminal.png" alt-text="Context menu showing Open in Terminal"::: @@ -219,8 +219,8 @@ In this tutorial, you published a console app. In the next tutorial, you create ::: zone-end -::: zone pivot="dotnet-core-3-1" +::: zone pivot="dotnet-core-3-1,dotnet-5-0" -This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page. +This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page. ::: zone-end diff --git a/docs/core/tutorials/testing-library-with-visual-studio-code.md b/docs/core/tutorials/testing-library-with-visual-studio-code.md index e29799ad82321..f41b2be9d48d9 100644 --- a/docs/core/tutorials/testing-library-with-visual-studio-code.md +++ b/docs/core/tutorials/testing-library-with-visual-studio-code.md @@ -1,13 +1,13 @@ --- title: Test a .NET class library using Visual Studio Code description: Learn how to use Visual Studio Code and the .NET CLI to create and run a unit test project for a .NET class library. -ms.date: 10/22/2021 +ms.date: 11/11/2022 zone_pivot_groups: dotnet-version recommendations: false --- # Tutorial: Test a .NET class library using Visual Studio Code -::: zone pivot="dotnet-7-0,dotnet-6-0" +::: zone pivot="dotnet-7-0" This tutorial shows how to automate unit testing by adding a test project to a solution. @@ -114,7 +114,7 @@ To create the test methods: Starting test execution, please wait... A total of 1 test files matched the specified pattern. - Passed! - Failed: 0, Passed: 3, Skipped: 0, Total: 3, Duration: 3 ms - StringLibraryTest.dll (net6.0) + Passed! - Failed: 0, Passed: 3, Skipped: 0, Total: 3, Duration: 3 ms - StringLibraryTest.dll (net7.0) ``` ## Handle test failures @@ -191,7 +191,7 @@ A library doesn't have to be distributed as a package. It can be bundled with a ::: zone-end -::: zone pivot="dotnet-5-0" +::: zone pivot="dotnet-6-0" This tutorial shows how to automate unit testing by adding a test project to a solution. @@ -237,7 +237,7 @@ Unit tests provide automated software testing during your development and publis - It applies the attribute to the `UnitTest1` class. - It applies the attribute to define `TestMethod1`. - 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 executed automatically when the unit test is run. + 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. 1. Add the test project to the solution. @@ -257,7 +257,7 @@ For the test project to work with the `StringLibrary` class, add a reference in ## Add and run unit test methods -When Visual Studio runs a unit test, it executes 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. +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: @@ -280,7 +280,7 @@ 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/UnitTest1.cs"::: + :::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/StringLibraryTest/UnitTest1.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). @@ -298,7 +298,7 @@ To create the test methods: Starting test execution, please wait... A total of 1 test files matched the specified pattern. - Passed! - Failed: 0, Passed: 3, Skipped: 0, Total: 3, Duration: 3 ms - StringLibraryTest.dll (net5.0) + Passed! - Failed: 0, Passed: 3, Skipped: 0, Total: 3, Duration: 3 ms - StringLibraryTest.dll (net6.0) ``` ## Handle test failures @@ -375,8 +375,8 @@ A library doesn't have to be distributed as a package. It can be bundled with a ::: zone-end -::: zone pivot="dotnet-core-3-1" +::: zone pivot="dotnet-core-3-1,dotnet-5-0" -This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page. +This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page. ::: zone-end diff --git a/docs/core/tutorials/with-visual-studio-code.md b/docs/core/tutorials/with-visual-studio-code.md index 4d6db06f9c3dc..cd6f32c528ec8 100644 --- a/docs/core/tutorials/with-visual-studio-code.md +++ b/docs/core/tutorials/with-visual-studio-code.md @@ -1,20 +1,20 @@ --- title: Create a .NET console application using Visual Studio Code description: Learn how to create a .NET console application using Visual Studio Code and the .NET CLI. -ms.date: 03/18/2022 +ms.date: 11/11/2022 zone_pivot_groups: dotnet-version recommendations: false --- # Tutorial: Create a .NET console application using Visual Studio Code -::: zone pivot="dotnet-7-0,dotnet-6-0" +::: zone pivot="dotnet-7-0" 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. You can follow this tutorial with a different code editor and run commands in a terminal if you prefer. ## Prerequisites * [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery). -* The [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0). +* The [.NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0). ## Create the app @@ -37,7 +37,7 @@ Create a .NET console app project named "HelloWorld". 1. In the **Terminal**, enter the following command: ```dotnetcli - dotnet new console --framework net6.0 + dotnet new console --framework net7.0 ``` The project template creates a simple application that displays "Hello World" in the console window by calling the method in *Program.cs*. @@ -131,14 +131,14 @@ In this tutorial, you created a .NET console application. In the next tutorial, ::: zone-end -::: zone pivot="dotnet-5-0" +::: zone pivot="dotnet-6-0" 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. You can follow this tutorial with a different code editor and run commands in a terminal if you prefer. ## Prerequisites -1. [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery). -2. The [.NET 5 SDK](https://dotnet.microsoft.com/download). If you install the .NET 6 SDK, install the .NET 5 SDK also, or some of the tutorial instructions won't work. For more information, see [New C# templates generate top-level statements](top-level-templates.md). +* [Visual Studio Code](https://code.visualstudio.com/) with the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery). +* The [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0). ## Create the app @@ -148,10 +148,12 @@ Create a .NET console app project named "HelloWorld". 1. Select **File** > **Open Folder** (**File** > **Open...** on macOS) from the main menu. -1. In the **Open Folder** dialog, create a *HelloWorld* folder and click **Select Folder** (**Open** on macOS). +1. In the **Open Folder** dialog, create a *HelloWorld* folder and select it. Then click **Select Folder** (**Open** on macOS). The folder name becomes the project name and the namespace name by default. You'll add code later in the tutorial that assumes the project namespace is `HelloWorld`. +1. In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. + 1. Open the **Terminal** in Visual Studio Code by selecting **View** > **Terminal** from the main menu. The **Terminal** opens with the command prompt in the *HelloWorld* folder. @@ -159,29 +161,34 @@ Create a .NET console app project named "HelloWorld". 1. In the **Terminal**, enter the following command: ```dotnetcli - dotnet new console --framework net5.0 + dotnet new console --framework net6.0 --use-program-main ``` -The template creates a simple "Hello World" application. It calls the method to display ":::no-loc text="Hello World!":::" in the console window. + The project template creates a simple application that displays "Hello World" in the console window by calling the method in *Program.cs*. -The template code defines a class, `Program`, with a single method, `Main`, that takes a array as an argument: + ```csharp + namespace HelloWorld; -```csharp -using System; + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } + ``` -namespace HelloWorld -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} -``` + The first time you edit a *.cs* file, Visual Studio Code prompts you to add the missing assets to build and debug your app. Select **Yes**, and Visual Studio Code creates a *.vscode* folder with *launch.json* and *tasks.json* files. -`Main` is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the *args* array. + > [!NOTE] + > If you don't get the prompt, or if you accidentally dismiss it without selecting **Yes**, do the following steps to create *launch.json* and *tasks.json*: + > + >* Select **Run** > **Add Configuration** from the menu. + >* Select **.NET 5+ and .NET Core** at the **Select environment** prompt. + + The code defines a class, `Program`, with a single method, `Main`, that takes a array as an argument. `Main` is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the *args* array. + + In the latest version of C#, a new feature named [top-level statements](../../csharp/fundamentals/program-structure/top-level-statements.md) lets you omit the `Program` class and the `Main` method. Most existing C# programs don't use top-level statements, so this tutorial doesn't use this new feature. But it's available in C# 10, and whether you use it in your programs is a matter of style preference. In the `dotnet new` command that you used to create the project, the `--use-program-main` option prevented top-level statements from being used. ## Run the app @@ -199,19 +206,11 @@ 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. -1. Open *Program.cs* by clicking on it. - - The first time you open a C# file in Visual Studio Code, [OmniSharp](https://www.omnisharp.net/) loads in the editor. - - ![Open the Program.cs file](media/with-visual-studio-code/open-program-cs.png) - -1. Select **Yes** when Visual Studio Code prompts you to add the missing assets to build and debug your app. - - ![Prompt for missing assets](media/with-visual-studio-code/missing-assets.png) +1. Open *Program.cs*. 1. Replace the contents of the `Main` method in *Program.cs*, which is the line that calls `Console.WriteLine`, with the following code: - :::code language="csharp" source="./snippets/with-visual-studio-6-0/csharp/Program.cs" id="MainMethod"::: + :::code language="csharp" source="./snippets/with-visual-studio/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. @@ -249,8 +248,8 @@ In this tutorial, you created a .NET console application. In the next tutorial, ::: zone-end -::: zone pivot="dotnet-core-3-1" +::: zone pivot="dotnet-core-3-1,dotnet-5-0" -This tutorial is only available for .NET 5 and .NET 6. Select one of those options at the top of the page. +This tutorial is only available for .NET 6 and .NET 7. Select one of those options at the top of the page. ::: zone-end