How to debug ASP.NET Core 2.0 source code
If you are a .net developer and love the fact you could debug your code easily by attaching the process to your code and go through it using keyboard shortcuts like F10 and F11. Well, the good news is that it becomes even easier to load assemblies that you don’t have it in your local such as:
- Microsoft.AspNetCore.Hosting
- Microsoft.AspNetCore.Environment
Microsoft team has already uploaded the PDBs of ASP.NET Core 2.0 on the Microsoft Symbol Servers. And if you are using Visual Studio 2017 15.3, Source Link Support for Windows PDB File Format, that is what you need to start with. Quote from Microsoft website:
Source Link is now supported for Windows PDB file format (in addition to Portable PDBs). Compilers that support it can put the necessary information in the Windows PDB file format and the debugger can retrieve source files based on that information.
Just create a new ASP.NET Core 2.0 Web application, remember you have to use Visual Studio 2017 15.3 or newer version.
Put a breakpoint on Startup class, and set a breakpoint on the ConfigureServices method, start the application and you will hit that breakpoint
Open the external code and select one of the external DLLs, let’s say Microsoft.AspNetCore.Hosting.dll.
Right click on Microsoft.AspNetCore.Hosting.dll and choose Load Symbols, Then the following dialog will be shown, start downloading the symbols from Microsoft Symbol Servers.
The following dialogue might pop up and ask whether you want to download it, select the appropriate option.
And voila, magic! you can now debug codes that are not even part of your solution.