Debugging NuGet Packages in Visual Studio Code: A Guide to Step-Through Debugging

Published: 27 March 2025
on channel: vlogize
90
like

Learn how to effectively debug `NuGet` packages within Visual Studio Code, enabling step-through debugging of your projects.
---
This video is based on the question https://stackoverflow.com/q/71140971/ asked by the user 'Kjara' ( https://stackoverflow.com/u/5333340/ ) and on the answer https://stackoverflow.com/a/71158846/ provided by the user 'Kjara' ( https://stackoverflow.com/u/5333340/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: debug nuget in Visual Studio Code

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Debugging NuGet Packages in Visual Studio Code: A Guide to Step-Through Debugging

Debugging can often feel like a daunting task, especially when working with multiple projects and packages. One common scenario developers face is wanting to step through the code of a project that's packaged as a NuGet and consumed by another project during debugging.

In this guide, we’ll explore how to enable debugging of your NuGet packages in Visual Studio Code, ensuring you can seamlessly debug both your library and the project that consumes it.

The Problem: Debugging Across Projects

When you have two projects, let's call them Project A and Project B, the challenge arises when:

Project A produces a NuGet package that you want to debug.

Project B consumes that NuGet package and you want to step through Project A’s code while debugging Project B.

Getting these two projects to work together in the debugger can be tricky, but it’s entirely possible.

The Solution: Enable Debugging for Your NuGet Package

Step 1: Update Your Project Files

The first step to resolving this issue is making sure both Project A and Project B are configured correctly to support debugging.

Open the .csproj File: You need to edit the project files for both Project A and Project B.

Set the Debug Type: Add the following line to your .csproj files, ensuring that it’s under the <PropertyGroup> section:

[[See Video to Reveal this Text or Code Snippet]]

This setting ensures that the debugging information in the pdb file can be used when running your projects.

Step 2: Utilize Your pdb File

In most configurations, if both projects are set to use the portable debugging symbols, you should not need to manually copy the pdb file over. Here’s how it works in most setups:

Automatic Detection: If your nuget.config for Project B correctly specifies the path to Project A, Visual Studio Code will search the project's folders for pdb files, including subfolders where the NuGet package is located.

Step 3: If Needed, Manual Copying

If your setup does not work as expected, you can manually ensure that debugging works by copying the pdb file from Project A to the output directory of Project B:

Copy Manually: Move the pdb file to Project B’s output directory.

Automate with NuGet: To automate this process in the future:

Include the pdb file in your NuGet package for Project A.

Modify your project’s .csproj file to add a target that copies the pdb file to the output directory automatically during the build process.

Step 4: Adjust Debug Settings

Lastly, ensure that your debugging settings in Visual Studio Code are set correctly:

Disable Just My Code: You may need to turn off the "Just My Code" feature in your Visual Studio Code debugger configuration. This allows VS Code to load symbols from the pdb files even if they are not part of the main program logic.

Conclusion

Debugging across multiple projects can initially seem intimidating, but with a few configuration tweaks, it can become a straightforward process. By setting the DebugType in your .csproj files and managing your pdb files effectively, you can step through all of your code, making the debugging process more efficient and less frustrating.

Now you’re equipped to debug your NuGet packages in Visual Studio Code effectively! If you have any questions, feel free to ask!


On this page of the site you can watch the video online Debugging NuGet Packages in Visual Studio Code: A Guide to Step-Through Debugging with a duration of hours minute second in good quality, which was uploaded by the user vlogize 27 March 2025, share the link with friends and acquaintances, this video has already been watched 90 times on youtube and it was liked by like viewers. Enjoy your viewing!