VS Code .NET Core and Docker Debugging Continued

In my previous post, I provided a step-by-step tutorial on how to setup debugging support for containerized .NET Core apps (via Docker) within VS Code.  For this post, I will cut out the tutorial portion and will instead point to some pre-packaged code that can be debugged with no setup required (other than the pre-requisites).

In the last post, I created a basic console application.  The code that we’ll see in this post builds on that example and also introduces container debugging for a .NET Core MVC application.  This was implemented in a similar fashion to the instructions outlined in the previous post, but instead of using “yo aspnet” to create a console application, I instead chose the option for a Basic MVC application.

If you would like to see a more thorough walkthrough of how to setup debugging support for Dockerized .NET Core apps, please see my previous post.

 

Pre-Requisites


Before we can start with this tutorial, we’ll need to install a couple things:

 

Once VS Code is installed, open the program and navigate to the Extensions section (square icon on left side).  Search for and then install the C# extension.  This will be necessary in order to have C# debugging support:

image002

 

Where’s the Code?


I’ll provide all of the steps to get this up and running, but for reference, all of my code for Docker and .NET core is located in the following repository: http://github.com/jixer/dockernetcore.

In this repository I have provided a number of examples of how to get things up and running with .NET Core and Docker using the Visual Studio IDE and/or VS Code.  If you would like to learn more about this topic, please browse through the code and README in the repository.  In addition, please leave me comments below if there are additional topics you would like me to explore.

The specific example we’ll be working with today is https://github.com/jixer/dockernetcore/tree/master/samples/VSCodeMvcDebugging

 

The Climax


“Alright Chris… I thought you said this post was going to be short and straight forward.  Enough build up already…  Let’s get on with the show!”

 

Step 1 – Download Code

Open a command prompt and navigate to a directory where you want to stage the files.

Now from the command prompt, run the following:

git clone http://github.com/jixer/dockernetcore

 

Step 2 – Open in VS Code

Open VS Code and then from the File menu choose “Open”.  Navigate to and then open the folder named “VSCodeMvcDebugging”.

**IMPORTANT: Make sure you open this exact folder.  The .vscode folder will only provide debugging and task support if it is at the root level of the folder you open in VS Code

 

Step 3 – Set a Break Point

Within VS Code, navigate to the HomeController.cs folder.  Place a breakpoint at line 13 in the Index method of the controller.

 

Step 4 – Start Debugging

With our breakpoint set, we’re ready to start debugging.  In order to start debugging, press [F5] from Windows or [fn] + [F5] if you’re using OSX.

After doing so, you should see a lot of information in the output window detailing the Docker build and Docker Compose tasks.  Once all of this is complete, your browser should open to the URL where Docker is forwarding traffic to our container from.  In addition, we should hit our break in VS Code!

 

Conclusion


Hope that this post helped you better understand easy it is to debug Dockerized .NET Core MVC applications.  For a more detailed walkthrough of the steps used to generate this example, please see this post: Debug Dockerized .NET Core Apps with VS Code.

In my GitHub repository (jixer/dockernetcore) I have provided a number of examples of how to get things up and running with .NET Core and Docker using the Visual Studio 2015 IDE and VS Code.  If you would like to learn more about this topic, please browse through the code and README in the repository.

Please use the social links below to share this post.  If you have any questions or comments, please leave a comment below.

Add your comment Add your comment

Previously