Debug Dotnet Core Application In Visual Studio Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys let us see how to create our first dot net core console application and how to debug it using visual studio code let's get started i have a folder called asp.net core on my desktop let's open shift right click open command window here in my previous session i have explained how to install dotnet sdk how to create dot net core web application and how to setup visual studio code for running.net projects if you haven't watched it please do watch it now to create the console application dotnet and we are going to create the new project so new and type of the project console and if you'd like to have the project name same as folder name where we are going to create the project in my case asp.net core then you can simply press the enter otherwise you can specify the project name i name it as first console app press enter template console app was created successfully and to run this application we need to move to the folder where we are having the project file so in my case it is first console app right so let's move to the folder cd first console app press enter now let's run it so to run the project we can simply say dotnet and use the command run there we go we can see the result hello world here let's open our project in visual studio code so for that just type code space dot there we go so here we have bin folder and object folder that we used to get when we create a console application and here we have project file and if you open it we can see target framework.net 6.0 before we discussing about program.cs here we have a prompt required assets to build and debug are missing so just click on yes now let's open program.cs and did you see something new here yes usually we used to have the program.cs file with the namespace of the project and program class and main method everything right and this code is equal to the code that we are having here so this is how we used to have the program.cs in previous versions of.net six right so here whatever the statement that we write are part of the body of main method and one more important update is here we don't see any using directives right like using system using systena typo like we don't see the importing of namespaces data 6.0 uses implicit using directives which means whenever we create a project compiler automatically adds a set of using directives based on the project type now let's see how to debug the code and before that here we have only one line of code so let me write few lines of code i am going to write the code to calculate the sum of the two numbers so here we have the code to calculate the sum of two numbers and here i am going to receive the input from user for a and b then we are going to save the result of a plus b in the total variable to receive the input from the terminal we need to make one change in launch.json so the file is available under dot vs code open launch.json for the console instead of internal console let's change it to integrated terminal save it let's close this now we are ready to debug our code so left side we have debug icon just click on it otherwise use ctrl shift d and here we have the green button otherwise you can press the f5 also just click on it now debug process has been started now just go to terminal and here it asks for enter first number right so just enter number 9 let's say then it ask for enter first number so okay it asks because i didn't change this text so that is okay just enter nine again so now that break point at line number eight is activated now here you can see that left side total integer value 0 and into a value 9 and into b value 9 right that's what we provided so inside this variables window we can see the values of the variables and also we can watch the variables so let's watch the value of total here so total and currently it is zero i'm sure you know the commands right like to execute the line by line code we can use the f10 so press f10 then now total is 18 that you can see in the watch window and after that let's and even before that you can see that here we have arcs strings of array right that we used to have in the main method as i said this code is part of the body of main method so the debugging is completed and here we can see the sum of two numbers is 18 right so this way you can do the debugging and now let us add a new class and how we can step into the other class and debug so for that i am going to create new class and say person dot cs here you can see that i am not importing any name space and also i'm not using the project name space so let me quickly create a class so class person let us define two properties city or now let's go to i am going to remove this entire code so let's create instance of person class so where p equal to new person here we can see that c sharp extension give us the intelligence to pass the name and edge right so let's pass krish and age let us call the display method result so where message equal to p dot display so i am writing the code in multiple lines so that we can debug with the different options and then console.to rightline message now let's have a breakpoint so here here here and we know that to debug the code we can press the f5 so this time i pressed f5 and this time we can see that our strings of array and p type of person is null because we are able to create the instance of person so just press f11 this time otherwise you can click on this up arrow so just press f11 now it comes to the constructor function of this person class so press f10 to execute line by line code then now again press left 11 to go to the display method and f10 then and here we have the message with value chris is 29 years old and the same thing will be printed to the terminal so go to terminal and we can see the same output this way you can debug the console application using visual studio code very easily
Info
Channel: CodeWellTech
Views: 6,888
Rating: undefined out of 5
Keywords: beginners, tutorial, learning, codewelltech, .net, .net core, .netcore console application, create .net core console application, debug .net core console application using visual studio code, debug .net core console application using Vscode, Vscode, .net core with Vscode, debug .net application using Vscode, vs code, Visual studio code .net, dotnet core, dotnet core console, debug .net core console app, learn .net core, debug .net, Debug Dotnet Core Application In Visual Studio Code
Id: PjQOWLOttbA
Channel Id: undefined
Length: 7min 14sec (434 seconds)
Published: Tue Feb 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.