{"id":6877,"date":"2022-08-23T15:48:51","date_gmt":"2022-08-23T15:48:51","guid":{"rendered":"https:\/\/codevoweb.com\/?p=6877"},"modified":"2022-08-27T15:18:33","modified_gmt":"2022-08-27T15:18:33","slug":"setup-vscode-to-debug-csharp-and-dotnet-programs","status":"publish","type":"post","link":"https:\/\/codevoweb.com\/setup-vscode-to-debug-csharp-and-dotnet-programs\/","title":{"rendered":"How to Setup VS Code to Debug C# and .NET Programs"},"content":{"rendered":"\n<p>Debugging is honestly one of the most&nbsp;important aspects of software development, as it allows developers to find and resolve bugs before deploying the software to production. Instead of putting <strong>Console.<\/strong><strong>WriteLine()<\/strong> statements on every corner of your code, VS Code has a lot of built-in functionalities, including debugging tools to help make the debugging process more efficient and simpler.<\/p>\n\n\n\n<p>In this article, you will configure VS Code to debug C# and .NET Core applications by installing the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-dotnettools.csharp\" target=\"_blank\" rel=\"noreferrer noopener\">C# extension by Microsoft<\/a>, creating debug configuration files, and setting breakpoints.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"850\" height=\"478\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/How-to-Setup-VS-Code-to-Debug-C-and-.NET-Programs.webp\" alt=\"How to Setup VS Code to Debug C# and .NET Programs\" class=\"wp-image-6938\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/How-to-Setup-VS-Code-to-Debug-C-and-.NET-Programs.webp 850w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/How-to-Setup-VS-Code-to-Debug-C-and-.NET-Programs-300x169.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/How-to-Setup-VS-Code-to-Debug-C-and-.NET-Programs-768x432.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/How-to-Setup-VS-Code-to-Debug-C-and-.NET-Programs-100x56.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/How-to-Setup-VS-Code-to-Debug-C-and-.NET-Programs-700x394.webp 700w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/figure>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id_8e57e3-43 .kb-table-of-content-wrap{padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px;border-color:#abb8c3;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;}.kb-table-of-content-nav.kb-table-of-content-id_8e57e3-43 .kb-table-of-contents-title-wrap{padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id_8e57e3-43 .kb-table-of-contents-title-wrap{color:#ffffff;}.kb-table-of-content-nav.kb-table-of-content-id_8e57e3-43 .kb-table-of-contents-title{color:#ffffff;font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id_8e57e3-43 .kb-table-of-content-wrap .kb-table-of-content-list{color:#ffffff;font-weight:regular;font-style:normal;margin-top:10px;margin-right:0px;margin-bottom:0px;margin-left:-5px;}<\/style>\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before you begin, you will need:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ASP.NET Core SDK installed locally, which you can do by <a href=\"https:\/\/dotnet.microsoft.com\/en-us\/download\" target=\"_blank\" rel=\"noreferrer noopener\">visiting the official .NET website<\/a>.<\/li><li>The latest version of&nbsp;<a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">VS Code<\/a>&nbsp;installed on your system.<\/li><li><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-dotnettools.csharp\" target=\"_blank\" rel=\"noreferrer noopener\">C# extension by Microsoft<\/a> installed<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"329\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-vs-code-extension.webp\" alt=\"csharp vs code extension\" class=\"wp-image-6487\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-vs-code-extension.webp 1010w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-vs-code-extension-300x98.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-vs-code-extension-768x250.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-vs-code-extension-100x33.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-vs-code-extension-700x228.webp 700w\" sizes=\"auto, (max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<p>The <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-dotnettools.csharp\" target=\"_blank\" rel=\"noreferrer noopener\">C# extension by Microsoft<\/a> offers powerful lightweight development tools to bring cross-platform C# development in VS Code. This extension also provides fantastic features like:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>C# editing support, including Syntax Highlighting, IntelliSense, and many more.<\/li><li>Debugging support for .NET Core applications<\/li><\/ul>\n\n\n\n<span id=\"ezoic-pub-video-placeholder-25\"><\/span>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1 &#8211; Create a Simple C# Console App<\/h2>\n\n\n\n<p>To avoid overcomplicating the debugging process, let&#8217;s use the .NET CLI to generate a simple C# console project with the&nbsp;<code>dotnet new &lt;TEMPLATE&gt;<\/code>command, where <code>&lt;TEMPLATE&gt;<\/code> is the application type.<\/p>\n\n\n\n<p>To generate the C# console application, execute the command <code>dotnet new console --name &lt;NAME&gt;<\/code> , the&nbsp;<em><code>&lt;NAME&gt;<\/code><\/em>&nbsp;parameter sets the name of the C# console project and the directory to be created. By default, the current directory name will be used if the <em><code>&lt;NAME&gt;<\/code><\/em>&nbsp;parameter is omitted.<\/p>\n\n\n\n<pre class=\"line-numbers language-shell\"><code>\ndotnet new console --name SimpleConsoleProject &amp;&amp; cd SimpleConsoleProject &amp;&amp; code .\n<\/code>\n<\/pre>\n\n\n\n<p>The above commands will execute the .NET project scaffolding tool to create a simple <em><strong>Hello World<\/strong><\/em> starter console application with some basic configuration and open the newly-created project with VS Code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"831\" height=\"460\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-console-project-example.webp\" alt=\"csharp console project example\" class=\"wp-image-6893\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-console-project-example.webp 831w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-console-project-example-300x166.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-console-project-example-768x425.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-console-project-example-100x55.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-console-project-example-700x387.webp 700w\" sizes=\"auto, (max-width: 831px) 100vw, 831px\" \/><\/figure>\n\n\n\n<p>After Visual Studio Code has finished setting up the workspace environment, the C# extension will immediately show a popup&nbsp;with the message &#8211;&nbsp;<strong><em>Required assets to build and debug are missing from &#8216;SimpleConsoleProject<\/em>&#8216;<\/strong>. Add them?&nbsp;&#8211; Click&nbsp;<strong>Yes<\/strong>&nbsp;to automatically generate and output the&nbsp;<code>launch.json<\/code>&nbsp;and&nbsp;<code>tasks.json<\/code>&nbsp;files into a&nbsp;<code>.vscode<\/code>&nbsp;folder.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note: <\/strong>This is only possible if you have the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-dotnettools.csharp\" target=\"_blank\" rel=\"noreferrer noopener\">C# extension by Microsoft<\/a> installed.<\/p><\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"572\" height=\"184\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generate-debugging-assets-notification-alert.webp\" alt=\"csharp generate debugging assets notification alert\" class=\"wp-image-6894\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generate-debugging-assets-notification-alert.webp 572w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generate-debugging-assets-notification-alert-300x97.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generate-debugging-assets-notification-alert-100x32.webp 100w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/figure>\n\n\n\n<p>If you don&#8217;t have the C# extension already installed, VS Code will prompt you to install it as soon as you open the C# file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"186\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-recommeded-extension.webp\" alt=\"csharp recommeded extension\" class=\"wp-image-6896\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-recommeded-extension.webp 671w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-recommeded-extension-300x83.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-recommeded-extension-100x28.webp 100w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2 &#8211; Generate the Build and Debug Assets for C#<\/h2>\n\n\n\n<p>If by any chance you didn&#8217;t get the VS Code popup notification to generate the build and debug files, click on the debugger tab on the left sidebar of VS Code and click on the <strong>Generate C# Assets for Build and Debug<\/strong> button.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note: <\/strong>This is only possible if you have the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-dotnettools.csharp\" target=\"_blank\" rel=\"noreferrer noopener\">C# extension by Microsoft<\/a> installed.<\/p><\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"523\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debug-panel-in-vs-code.webp\" alt=\"debug panel in vs code\" class=\"wp-image-6897\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debug-panel-in-vs-code.webp 565w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debug-panel-in-vs-code-300x278.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debug-panel-in-vs-code-100x93.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debug-panel-in-vs-code-486x450.webp 486w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/figure>\n\n\n\n<p>Clicking the button will generate the files needed to build, debug and launch the C# application.<\/p>\n\n\n\n<p>The&nbsp;<code>tasks.json<\/code>&nbsp;file contains the <a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/tasks\" target=\"_blank\" rel=\"noreferrer noopener\">configurations for tasks<\/a> (e.g. build, publish, watch, launch, etc) that are to be executed by VS Code.<\/p>\n\n\n\n<p>The&nbsp;<code>launch.json<\/code>&nbsp;file contains the <a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/debugging#_launch-configurations.\" target=\"_blank\" rel=\"noreferrer noopener\">debugging configuration information<\/a>.<\/p>\n\n\n\n<p>These two files allow Visual Studio Code to build and launch the project in debug mode.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"563\" height=\"515\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generated-debug-assets.webp\" alt=\"csharp generated debug assets\" class=\"wp-image-6895\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generated-debug-assets.webp 563w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generated-debug-assets-300x274.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generated-debug-assets-100x91.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/csharp-generated-debug-assets-492x450.webp 492w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/figure>\n\n\n\n<p>Now open the <strong>launch.json<\/strong> file and the VS Code debugger panel. On the debugger panel, click on the dropdown list adjacent to the play button to see the available tasks.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"603\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-1024x603.webp\" alt=\"vs code debug lunch json file\" class=\"wp-image-6899\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-1024x603.webp 1024w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-300x177.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-768x452.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-1536x904.webp 1536w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-100x59.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-700x412.webp 700w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file-1600x942.webp 1600w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/vs-code-debug-lunch-json-file.webp 1835w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>.vscode\/launch.json<\/strong><\/p>\n\n\n\n<pre class=\"line-numbers language-json\"><code>\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \/\/ Use IntelliSense to find out which attributes exist for C# debugging\n      \/\/ Use hover for the description of the existing attributes\n      \/\/ For further information visit https:\/\/github.com\/OmniSharp\/omnisharp-vscode\/blob\/master\/debugger-launchjson.md\n      \"name\": \".NET Core Launch (console)\",\n      \"type\": \"coreclr\",\n      \"request\": \"launch\",\n      \"preLaunchTask\": \"make this work\",\n      \/\/ If you have changed target frameworks, make sure to update the program path.\n      \"program\": \"${workspaceFolder}\/bin\/Debug\/net6.0\/SimpleConsoleProject.dll\",\n      \"args\": [],\n      \"cwd\": \"${workspaceFolder}\",\n      \/\/ For more information about the 'console' field, see https:\/\/aka.ms\/VSCode-CS-LaunchJson-Console\n      \"console\": \"internalConsole\",\n      \"stopAtEntry\": false\n    },\n    {\n      \"name\": \".NET Core Attach\",\n      \"type\": \"coreclr\",\n      \"request\": \"attach\"\n    }\n  ]\n}\n\n<\/code>\n<\/pre>\n\n\n\n<p>Let&#8217;s evaluate the first configuration (<strong>.NET Core Launch (console)<\/strong>) in the list. It launches the program <code>${workspaceFolder}\/bin\/Debug\/net6.0\/SimpleConsoleProject.dll<\/code> , which  is the <code>.dll<\/code> that will be generated when we build the application. You can also pass arguments to the <strong>main<\/strong> method through the <code>\"args\":[]<\/code> property.<\/p>\n\n\n\n<p>It also uses the internal console compared to <a href=\"https:\/\/visualstudio.microsoft.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visual Studio<\/a> which uses an external console.<\/p>\n\n\n\n<p>The second configuration (<strong>.NET Core Attach<\/strong>) allows you to attach the VS Code debugger to a running instance of a .NET application.<\/p>\n\n\n\n<p>Now open the <code>tasks.json<\/code> and the <code>launch.json<\/code> files side-by-side to help us understand them better.<\/p>\n\n\n\n<p>We have the <code>\"preLaunchTask\": \"build\"<\/code> in the <code>launch.json<\/code> file which corresponds to the <code>\"label\": \"build\"<\/code> task in the <code>tasks.json<\/code> .<\/p>\n\n\n\n<p>The <code>\"label\": \"build\"<\/code> task runs the <code>dotnet build<\/code> command and specifies the project to build in the <code>\"args\": []<\/code>  property.<\/p>\n\n\n\n<p>We also have two additional tasks <code>\"label\": \"publish\"<\/code> and <code>\"label\": \"watch\"<\/code> .<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-1024x576.webp\" alt=\"launch and task jsons for vs code\" class=\"wp-image-6898\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-1024x576.webp 1024w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-300x169.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-768x432.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-1536x864.webp 1536w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-100x56.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-700x394.webp 700w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code-1600x900.webp 1600w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/launch-and-task-jsons-for-vs-code.webp 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>.vscode\/tasks.json<\/strong><\/p>\n\n\n\n<pre class=\"line-numbers language-json\"><code>\n{\n  \"version\": \"2.0.0\",\n  \"tasks\": [\n    {\n      \"label\": \"build\",\n      \"command\": \"dotnet\",\n      \"type\": \"process\",\n      \"args\": [\n        \"build\",\n        \"${workspaceFolder}\/SimpleConsoleProject.csproj\",\n        \"\/property:GenerateFullPaths=true\",\n        \"\/consoleloggerparameters:NoSummary\"\n      ],\n      \"problemMatcher\": \"$msCompile\"\n    },\n    {\n      \"label\": \"publish\",\n      \"command\": \"dotnet\",\n      \"type\": \"process\",\n      \"args\": [\n        \"publish\",\n        \"${workspaceFolder}\/SimpleConsoleProject.csproj\",\n        \"\/property:GenerateFullPaths=true\",\n        \"\/consoleloggerparameters:NoSummary\"\n      ],\n      \"problemMatcher\": \"$msCompile\"\n    },\n    {\n      \"label\": \"watch\",\n      \"command\": \"dotnet\",\n      \"type\": \"process\",\n      \"args\": [\n        \"watch\",\n        \"run\",\n        \"--project\",\n        \"${workspaceFolder}\/SimpleConsoleProject.csproj\"\n      ],\n      \"problemMatcher\": \"$msCompile\"\n    },\n    {\n      \"label\": \"test\",\n      \"command\": \"dotnet\",\n      \"type\": \"process\",\n      \"args\": [\"test\", \"${workspaceFolder}\/SimpleConsoleProject.csproj\"],\n      \"problemMatcher\": \"$msCompile\"\n    },\n    {\n      \"label\": \"make this work\",\n      \"dependsOn\": [\"build\", \"test\"],\n      \"problemMatcher\": \"$msCompile\"\n    }\n  ]\n}\n\n<\/code>\n<\/pre>\n\n\n\n<p>You are also allowed to add your own tasks. For example: create a task called <code>\"label\": \"test\"<\/code> and <code>\"label\": \"make this work\"<\/code> that will depend on the build and test tasks.<\/p>\n\n\n\n<p>Next, add the <code>\"label\": \"make this work\"<\/code> task to the <code>\"preLaunchTask\": \"\"<\/code> property in the <code>launch.json<\/code> file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"588\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-1024x588.webp\" alt=\"add more task to the vs code debug assets\" class=\"wp-image-6891\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-1024x588.webp 1024w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-300x172.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-768x441.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-1536x883.webp 1536w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-100x57.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-700x402.webp 700w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets-1600x919.webp 1600w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-more-task-to-the-vs-code-debug-assets.webp 1878w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3 &#8211; Create a Breakpoint<\/h2>\n\n\n\n<p>A&nbsp;<strong>breakpoint&nbsp;<\/strong>is a point in the code where you want the code execution to stop to enable you to inspect the memory addresses and get detailed insight into the state of the memory. <\/p>\n\n\n\n<p>For example, if you set a breakpoint at line <strong>5<\/strong> and run the code in debugger mode, the code will execute and freeze at line <strong>5<\/strong>.<\/p>\n\n\n\n<p>To create a breakpoint, click on the gutter adjacent to the line numbers in the editor. When you hover your mouse across the gutter, you will see red circles appearing on each line. <\/p>\n\n\n\n<p>Now click on the red circle on the gutter where you want to stop the execution of the code to activate the breakpoint on that line.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"563\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code-1024x563.webp\" alt=\"add breakpoints to debug vs code\" class=\"wp-image-6932\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code-1024x563.webp 1024w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code-300x165.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code-768x422.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code-100x55.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code-700x385.webp 700w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/add-breakpoints-to-debug-vs-code.webp 1201w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4 &#8211; Start the VS Code Debugger<\/h2>\n\n\n\n<p>Now start the debugger by clicking on the play button in the VS Code debugger panel or using <strong>F5<\/strong>. This will run the program and pause the code at the first breakpoint where you can inspect the state of the variables in the <strong>VARIABLES<\/strong>&nbsp;pane. <\/p>\n\n\n\n<p>Also, you can hover your mouse on the line of the current breakpoint highlighted in yellow to inspect the values of the variable.<\/p>\n\n\n\n<p>Next, use the debugger navigation buttons to move the execution of the code line by line.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-1024x576.webp\" alt=\"debugging with the csharp extension\" class=\"wp-image-6950\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-1024x576.webp 1024w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-300x169.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-768x432.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-1536x864.webp 1536w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-100x56.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-700x394.webp 700w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension-1600x900.webp 1600w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/debugging-with-the-csharp-extension.webp 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Meanwhile, the&nbsp;<strong>WATCH<\/strong>&nbsp;panel in VS Code lets you see the value of a variable or an expression from the program&#8217;s current state. The <strong>WATCH<\/strong>&nbsp;panel is useful if you want to see some information as you are moving the execution of your program from line to line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5 &#8211; Install the Recommended VS Code Extensions<\/h2>\n\n\n\n<p>Now let&#8217;s discourse the different extensions that I will recommend when you are coding in C# and Dotnet.  To create an IDE-like experience in Visual Studio Code, these are the extensions I will install without thinking twice.<\/p>\n\n\n\n<p>To get a full list of all extensions, follow the <a href=\"\/top-vs-code-extensions-for-csharp-and-dotnet\">Top 10 VS Code Extensions for C# and .NET Development<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1 &#8211; <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=josefpihrt-vscode.roslynator\" target=\"_blank\" rel=\"noreferrer noopener\">Roslynator<\/a><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"329\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Roslynator-vs-code-extension.webp\" alt=\"Roslynator vs code extension\" class=\"wp-image-6494\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Roslynator-vs-code-extension.webp 1024w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Roslynator-vs-code-extension-300x96.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Roslynator-vs-code-extension-768x247.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Roslynator-vs-code-extension-100x32.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Roslynator-vs-code-extension-700x225.webp 700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2 &#8211; <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=formulahendry.dotnet-test-explorer\" target=\"_blank\" rel=\"noreferrer noopener\">.NET Core Test Explorer<\/a><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"328\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/dotNET-Core-Test-Explorer.webp\" alt=\"dotNET Core Test Explorer\" class=\"wp-image-6489\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/dotNET-Core-Test-Explorer.webp 916w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/dotNET-Core-Test-Explorer-300x107.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/dotNET-Core-Test-Explorer-768x275.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/dotNET-Core-Test-Explorer-100x36.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/dotNET-Core-Test-Explorer-700x251.webp 700w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">3 &#8211; <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=Fudge.auto-using\" target=\"_blank\" rel=\"noreferrer noopener\">Auto-Using for C#<\/a><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"984\" height=\"330\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Auto-Using-for-Csharp-extension.webp\" alt=\"Auto-Using for Csharp extension\" class=\"wp-image-6485\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Auto-Using-for-Csharp-extension.webp 984w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Auto-Using-for-Csharp-extension-300x101.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Auto-Using-for-Csharp-extension-768x258.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Auto-Using-for-Csharp-extension-100x34.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/Auto-Using-for-Csharp-extension-700x235.webp 700w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4 &#8211; <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=adrianwilczynski.namespace\" target=\"_blank\" rel=\"noreferrer noopener\">C# Namespace Autocompletion<\/a><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1006\" height=\"330\" src=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/C-Namespace-Autocompletion-vs-code-extension.webp\" alt=\"C# Namespace Autocompletion vs code extension\" class=\"wp-image-6486\" srcset=\"https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/C-Namespace-Autocompletion-vs-code-extension.webp 1006w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/C-Namespace-Autocompletion-vs-code-extension-300x98.webp 300w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/C-Namespace-Autocompletion-vs-code-extension-768x252.webp 768w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/C-Namespace-Autocompletion-vs-code-extension-100x33.webp 100w, https:\/\/codevoweb.com\/wp-content\/uploads\/2022\/08\/C-Namespace-Autocompletion-vs-code-extension-700x230.webp 700w\" sizes=\"auto, (max-width: 1006px) 100vw, 1006px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this comprehensive guide, you learned how to set up VS Code to debug C# and .NET programs. With this knowledge, you can start debugging your projects with ease in VS Code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Debugging is honestly one of the most&nbsp;important aspects of software development, as it allows developers to find and resolve bugs before deploying the software to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":6938,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[79],"tags":[81,80,30],"class_list":["post-6877","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-2","tag-net","tag-c-3","tag-vscode"],"acf":[],"_links":{"self":[{"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/posts\/6877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/comments?post=6877"}],"version-history":[{"count":0,"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/posts\/6877\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/media\/6938"}],"wp:attachment":[{"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/media?parent=6877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/categories?post=6877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codevoweb.com\/wp-json\/wp\/v2\/tags?post=6877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}