What is a Source Server and How Does it Help Debug NuGet?
by Eric Seng, on Feb 9, 2022 10:51:00 AM
Have you ever consulted the source code of an NuGet package for debugging?
Checking the original source files used to build a package can help during the debugging process, especially considering the multiple iterations a NuGet package can go through.
In this article, we’ll quickly explain what a source server is, what SourceLink is, and how it can help with debugging NuGet packages.
What is a source server?
Per Microsoft, a source server “enables a client to retrieve the exact version of the source files that were used to build an application.”
A module’s source code changes between versions as it continues to develop over time; patches, major upgrades, etc.. The source server retrieves the appropriate files from the source control server.
To use source server, the application must be source indexed; e.g. must embed version-control path and version-number information into a PDB file. A PDB file, also known as Symbols, helps map the compile code and point to the right file.
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 source server debugging.
What is SourceLink?
The similar names between source server and SourceLink reflect their connection: SourceLink is a technology that allows authors of NuGet libraries (like those who have published to NuGet.org) to provide source debugging for other users.
Instead of embedding information in the PDB files, SourceLink relies on a NuGet package’s metadata element to locate code files in a web-based Git repository.
How does source serving help with debugging?
Source indexing help the debugger find the right source files (from the source server). Because the source 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 than attempt a tedious debugging process.
Symbol and source 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: