You may encounter the need to debug into a dependency that is NuGet package. If this NuGet package is proprietary, you need to contact the vendor. However, if the NuGet package is open source, perhaps on GitHub, then you have all the tools you need to debug into it. Debugging into an open source NuGet package is what this article is about.
We are going to use Rhyous.StringLibrary for this example. It is a simple open source project that provides some common extensions to strings. These are extensions that are often found duplicated in many different projects and sometimes multiple times in the same project.
Step 1 – Check out the Source
Check out the repo from GitHub. You need a Git client. If you don’t have one, you can use GitHub Desktop or the one that is included in the Windows install of Git.
- Check out the repository:
git fetch https://github.com/rhyous/StringLibrary.git
Step 2 – Build the Solution
- Open the StringLibrary.sln in Visual Studio.
- Click Build.
- Go to the output directory and copy the dll and pdb files.
Step 3 – Copy the dll and pdb to your solution
If you go to your project that references the dll, find and highlight the reference and go to properties, you can see the full path to the referenced dll.
- Go to the solution folder of the project you are working on.
- Go to your project that references the dll.
- Under References, locate the dll.
- Go to Properties of the dll reference by pressing F4.
- Note the path to the dll.
- Go into the Packages directory.
- Find the folder for Rhyous.StringLibrary.
- Locate the dll folder.
- Rename the existing rhyous.stringlibrary.dll to rhyous.stringlibrary.dll.orgininal.
- Copy the compiled dll and pdb from Step 2 to this folder.
- Clean and build your solution.
Step 4 – Add a breakpoint
You should now be able to step into the Rhyous.StringLibrary source from your project.
Note: If you have two instances of Visual Studio open, one for your project and one for Rhyous.StringLibrary project, you may think you put the break point in on the one with the SimplePluginLoader project. You don’t. You don’t even need the Rhyous.StringLibrary project open, unless you need to make a change and recompile and recopy the dll and pdb to the packages directory.
- Debug your poject.
- Put a break point on the call to Rhyous.StringLibrary you would like to step into.
- Step into the call to Rhyous.StringLibrary.
Once you have stepped into the call, you should see it’s source.
Continue stepping into or over or whatever you would like.
Once you are in the source, you can add breakpoints.