Debug ASP.NET CORE 2.0 Source Code

In Visual Studio 2017, symbols and source links can be used to debug the source code in ASP.NET Core 2.0. In this article, we will focus on how to use source links to debug ASP.NET Core sources.

What is a source link?
Like me, you may have noticed the PDB file that is created when the code is compiled. These files save symbol information, which can optionally be used to support debugging of external source code. Certain types of symbol files may contain some source code or source code mapping.

For a long time, Microsoft has hosted symbol servers, which store symbol files released by Microsoft products (such as .NET Framework and ASP.NET Core). Visual Studio supports dynamic download of symbols. To do this, you must disable the “Enable Only My Code” option in the “Debug” -> “General” option. By default, this option is enabled in Visual Studio.

For more information about symbols, symbol servers, etc., please refer to this MSDN link.

The source link allows you to embed the name and location list of the called method in the symbol file. It can identify the file containing the code and where the file can be retrieved. ASP.NET Core (not .NET Core) now supports source links and provides links to hosted code on GitHub.

Enable and use source links
The first requirement is to update Visual Studio 2017 to the latest version (15.3), which adds support for source links. If you install this option, in the “Debug” -> “General” option, you will see “Enable source link support”.

In addition to ensuring that “Enable Only My Code” is disabled, you must also enable the Microsoft symbol server. In the “Debug” -> “Symbols” option, you can download the symbol file Enable “Microsoft Symbol Server” in the location list.

When you enable the symbol server, you need to accept the performance impact that may be introduced during debugging.

After setting up, prepare to debug ASP.NET Core source code. To test this, I created a default ASP.NET Core 2.0 MVC project in Visual Studio. Then I added a breakpoint to the Index method on HomeController. Then start debugging the application. You may see this message when debugging for the first time.

This is the symbol file being downloaded. It may take a while to complete.

Once the application runs to a breakpoint in your code, you can navigate to the call stack to see all external ASP.NET code being executed.

If you double-click any of these calls, the editor will use symbols to determine the frame location of the code. Using the link in the symbol file, Visual Studio will download the source file from GitHub. When the source link needs to download the source code, you will see the following warning dialog box:

You can select the first “download source and continue debugging” option and continue to use The file is debugged. You can choose the second option, which will download the file and disable the warning for the next file download.

After downloading the source file, it will be displayed in the location corresponding to the stack you selected.

You can also add your own breakpoints elsewhere in the file, and then set them to hit when debugging the application. Even if we stop debugging and restart, this still seems to be valid.

Summary
Very nice, debugging external source code in ASP.NET Core is very easy. Through this feature, we can get more value, so that we can debug the ASP.NET Core source code and understand the internal workings.

Reference materials:

Debugging ASP.NET Core 2.0 Source Code

Original address: http://www.cnblogs.com/tdfblog/p/debugging -asp-net-core-2-source.html

Leave a Comment

Your email address will not be published.