How to debug code in a nuget package created by me

debug nuget package pdb
replace nuget package with local dll
nuget debug and release
nuget sourcelink
nuget package missing symbols
visual studio navigate to nuget code
how to use pdb files for debugging
how to debug third-party dll

I have a nuget package I created and installed in another solution but now I need to debug de code of the package when called from my new solution.

I tried referencing the solution of the package but is not working.

I am using Visual Studio 2013.

Debugging into a NuGet package, It provides tools to create and reference packages. of time but it also has a disadvantage: as the code base of your Nuget packages grows, the list of bugs as well. Add symbol servers under “Symbol file (.pdb) locations”. Debugging a NuGet Package NuGet adds and manages DLL files in your .NET project, but not any source or symbol files. This can make debugging packages without extra tools like ReSharper rather challenging, since you’re basically left analyzing the source code without stepping through it at runtime.

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.

e.g copy from

ExternalNugetPackage\bin\Debug\

to

ProjectDirectory\Packages\ExternalNugetPackage.1.0.0\lib\net4.5

How To Debug A .NET Core Nuget Package?, This is a short guide to debugging a NuGet package by replacing it with a local build. One of NuGet's limitations revealed itself to me on a recent project connect assembly from the DLL to the source code while debugging. Setting Visual Studio to use a local feed for NuGet packages Creating the local NuGet feed folder. The first step required is to create a local NuGet folder to host the debug NuGet packages. The word local here does not have to be taken literally – a network share or even a file share on Azure (AWS / etc.) will work.

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):

  1. Create "*.symbols.nupkg".
  2. Deploy symbol package to SymbolSource server.
  3. Configure IDE, Package consumers can add https://nuget.smbsrc.net/ to your symbol sources in Visual Studio.
  4. Add required Library to project using NuGet (from our SymbolSource server).
  5. Debug.

For the detail info, you can refer to Creating symbol packages.

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)

Debugging a NuGet Package with a Locally-built DLL & PDB, The .pdb file that was built alongside the .dll you want to debug How do I find the source code for a given Nuget package? What usally works for me is to go to the Nuget page for the package and click on Project Site. Nuget is a package manager for .NET. It provides tools to create and reference packages. The Nuget official packages repository is nuget.org. Each Nuget package contains .NET binaries that will be referenced by the project where you install the package.

For Visual Studio 2017 and your nuget package source code hosted on GitHub or BitBucket:

1) Enable full debug information in *.csproj file:

  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

or right-click project properties, build, advanced, output debugging information - set to full.

2) 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:

  <ItemGroup>
    <PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.2" PrivateAssets="All" /> 
  </ItemGroup>

More info here

3) In tools - options - debugging, disable "Enable Just My Code", and enable "Suppress JIT optimization on module load (Managed Only)".

After this, you should be able to step inside methods from your nuget package dll.

Debugging 3rd Party Nuget Packages, Starting today, you can publish symbol packages to the NuGet.org symbol server. Compile your code using Visual Studio 2017 15.9 to generate the portable PDBs. Create the .snupkg using pack with your tool of choice. Under Symbol file (.pdb) locations, add a new symbol server location by  Before we talk about debugging NuGet packages we need to talk about what we need to actually debug our code and how the debugger uses the various assets we have available to help us do that. The following items are pretty well common for most compiled languages on windows and linux platforms.

Improved package debugging experience with the NuGet.org , NET Framework code as well. Source Link provides source control metadata to create a great debugging experience. Note. Visual Studio for Mac  Debugging 3rd Party Nuget Packages. The following is a braindump of what options there are for debugging Nuget packages not maintained by you. It’s not particulary polished, but maybe it’ll help someone. So you need two things to step-through code: The souce code, and… The .pdb file that was built alongside the .dll you want to debug; 1.

Debugging into NuGet packages with Source Link, Yeah, me too. Before we talk about debugging NuGet packages we need to talk You can either step right into the method you want to investigate and ReSharper will automatically create the source code for you by using  NuGet.org symbol server only accepts the new symbol package format .snupkg. Take a look at NuGet.org symbol package constraints for more info. Consume snupkg from NuGet.org in Visual Studio. You will need Visual Studio 2017 15.9 to consume .snupkg from NuGet.org symbol server. In Visual Studio, open Tools > Options > Debugging > Symbols (or Debug > Options > Symbols).

Debugging NuGet Packages, Lots of NuGet packages have their source code on GitHub, so it would be very #Create a NuGet package with SourceLink enabled. Enabling source code debugging for your NuGet packages with GitLink September 23, 2015 Coding continuous integration , gitlink , msbuild , nuget , xUnit Recently on Twitter, someone was complaining that their CI builds were failing due to SymbolSource.org either being down or rejecting their packages.

Comments
  • The way I used to debug a nuget package if I created it was by adding it to the solution I am working on as another project and experiment with it, when I am happy with all the results, I'd push it to nuget
  • related: How to debug into my nuget package deployed from TeamCity?
  • From every other crazy solution I have tried and wasted my time with this is the simplest. I just extract my nuget.symbols.nupkg and dump the pdb in the bin directory next to the downloaded dll , un-check Enable just my code and I can step into my NuGet package. I did not even need to add the source files into the solution "Debug Source Files" panel. I don't understand why everybody suggested over the top, extremely complicated solutions? +1 for you mate!
  • @ppumkin Thanks for the information about Enable just my code. I've updated my answer to include this information.
  • I have tried this again on another project and it says the source code is missing.. so last time I included the source in the properties and it worked but this new project I didnt so I cannot step into the code - But you will also get "source code missing" when trying to step in.. you can then click "navigate to source" and select the folder with all the source files (in my case unpacked from the nuget package) boom - stepped into code. Another way is to just open the file in Visual Studio. File -> Open (the exact source file)
  • If I switch Enable Just My Code off, I end up having to step through a bunch of .NET framework stuff before I get anywhere near my code. It's not ideal, but disabling Optimize code when building the NuGet package is the only reasonable option for me. Just have to remember to switch it back for deployment.
  • This just does not work- I have no idea why.. but I have spent too much time trying to figure it out when it should be simple for us. Putting the pdb file in the bin directory of the built project.. worked straight away for me (just had to un-check Enable My Code"
  • This is a great answer! SourceLink has been taken over by microsoft now so heres the new repo github.com/dotnet/sourcelink. The only bummer is this requires packagereference and .NET Core.
  • What does Suppress JIT optimization on module load (Managed Only) do?
  • When the package is JIT optimized, the code being executed is slightly different (optimized) than the source code (e.g. some small methods might be inlined, etc), and stepping in the debugger would not reflect lines of code exactly.