user

What is a Symbol Server and How Does it Help Debug NuGet?

Introduction

Eric Seng

Eric Seng


LATEST POSTS

What are NuGet Package Vulnerabilities and How to Manage Them 09th October, 2023

How to Debug NuGet Packages with Symbols and Source Link Painlessly 02nd October, 2023

NuGet

What is a Symbol Server and How Does it Help Debug NuGet?

Posted on .

Have you ever consulted the symbol files of a NuGet package for debugging?

Checking the symbol files used to build a package can be incredibly valuable during the debugging process, especially given the multiple iterations a NuGet package can undergo.

Symbol serving is not automatically configured, however, in Visual Studio. Some major private repositories don’t even offer symbol-serving functionality.

In this article, we’ll quickly explain what a symbol server is, what SourceLink is, and how it can assist in debugging NuGet packages.

What is a Symbol Server?

Symbols files actually predate NuGet (and .NET as a whole) by at least a few decades. They were originally designed for when disk space was at a premium, and symbols were rarely included in released software. This made debugging a pain.

This is where a Symbol Server came in. When building a library, the compiler will embed the same random, unique identifier (basically a GUID) in both the .dll and .pdb files. If you uploaded the .pdb file to a Symbol Server, you could later retrieve it using that unique identifier embedded in the .dll file.

That’s how a debugger like Visual Studio can load symbol files when an application crashes; you don’t need to have all of the

A private NuGet repository like ProGet can index and serve PDB files but will have to be configured ahead of time.

Once your repository is configured for source serving, your dev environment (ex. Visual Studio) must also be configured to allow symbol server debugging.

What is SourceLink?

Remember how a .pdb will map compiled assemblies (i.e., the .dll and .exe files) to source code (i.e., the .cs files)? This “map” requires having the exact version of the code files that were used to build the assemblies. So if you’re using a symbol server… where do the code files come in?

This is where Source Link comes in. When you build a NuGet package with Source Link enabled a Git Repository URL and Commit ID will be embedded in the package metadata. This allows Visual Studio to locate the required code files for debug time.

To enable Source Link in your own .NET project, you just need to set a few properties and then add a NuGet package specific to your Git repository (e.g. Microsoft.SourceLink.GitHub).

How Does Symbol Serving Help with Debugging?

Symbol Servers and Symbols go hand-in-hand.

Symbol serving helps the debugger find the right source files (from the symbol server). Because the symbol indexing information is stored in the PDB files, you must have symbols loaded.

If you want to debug into the source code associated with a PDB file, for example, the SourceLink build tool can embed source file URLs (or the files themselves) during compilation.

Better NuGet debugging

There aren’t many ways to debug a NuGet package. Most developers will likely avoid using NuGet libraries rather than attempt a tedious debugging process.

Symbol serving, however, shows it is possible when configured correctly.

Debugging is important, but there’s a lot more to learn about NuGet packages to successfully use them on the Enterprise level. Sign up for our new ebook:

Eric Seng

Eric Seng

Navigation