To debug any dll you need the symbol file of it (.pdb). If you build your project in the debug configuration you will see that those files are generated and put in the build output folder.
Visual studio loads those symbol files from different places as described here. The easiest way to debug your nuget packages is to put the .pdb files of the packages in the build output folder of the project you want to debug.
If the code you are trying to debug is classified as non-user code you need to uncheckJust My Code in the debugging options.
To distinguish user code from non-user code, Just My Code looks at
symbol (.pdb) files and program optimizations. The debugger considers
code to be non-user code when the binary is optimized or when the .pdb
file is not available.
Three attributes also affect what the debugger considers to be My
Code:
DebuggerNonUserCodeAttribute tells the debugger that the code it is applied to is not My Code.
DebuggerHiddenAttribute hides the code from the debugger, even if Just My Code is turned off.
DebuggerStepThroughAttribute tells the debugger to step through the code it is applied to, rather than step into the code.
How to debug code in a nuget package created by me
Just as NtFreX answered, "To debug any dll you need the symbol file of it (.pdb). ". So you can create symbol packages which allow consumers to step into your package code in the Visual Studio debugger.
The way we do it (and works):
Create "*.symbols.nupkg".
Deploy symbol package to SymbolSource server.
Configure IDE, Package consumers can add https://nuget.smbsrc.net/ to your symbol sources in Visual Studio.
Add required Library to project using NuGet (from our SymbolSource server).
If these packages are not suitable for publishing on NuGet Gallery/SymbolSource, you can put the *.nupkg and *.symbols.nupkg files on a local disk.
Note: Add the source code to the Debug Source Files for the solution that references the package(Right click on Solution, select Properties...Common Properties...Debug Source Files, and add the root source directory for the relevant binary reference)
I got this working by building the project the nuget package originated from in debug mode, then just copying the pdb and dll from the debug directory to the location of the nuget dll within the project I wanted to debug it in.
or right-click project properties, build, advanced, output debugging information - set to full.
To enable automatic source download and stepping for your nuget package dll, add nuget package SourceLink.Create.CommandLine to your project, or add it manually into *.csproj file:
I got this working by packing the package in debug mode and installing it from my local NuGet source. Then when you debug you can step into your library. You can add your NuGet local source that points to your local folder in Tools -> Options -> Nuget Package Manager -> Package Sources