How to Debug into My Nuget Package Deployed from Teamcity

How to debug into my nuget package deployed from TeamCity?

Traditional method

  1. Put the pdb in the NuGet package alongside the dll.
  2. Add the source code to the Debug Source Files for the solution that references the package.

This means you'll be able to step through code and view exceptions, but you might have to find a file on disk and open it before you can set a breakpoint. Obviously you need to be careful that the source is at the right revision.

More detail on step

If you're currently packaging without a Nuspec, you'll need to create a Nuspec, then add the pdb to the list of files in the lib folder "NuGet spec" may be a useful command for generating the initial spec as defined in NuGet docs. Then ensure the Team City Nuget Pack step is referencing your new nuspec.

More detail on step 2

When you have a solution open, right click on Solution, select Properties...Common Properties...Debug Source Files, and add the root source directory for the relevant binary reference. Or see MSDN.
Note, you can't open the solution properties while debugging.

Still not hitting breakpoints?

Try disabling this from Tools->Options:
Disable exact source match


Modern way for public or private repos

To ensure the exact version of the source is available, embed it at build time.

From Visual Studio 2017 15.5+ you can add the EmbedAllSources property:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EmbedAllSources>true</EmbedAllSources>

Modern way for public repos

To keep your nuget and library size small, you can use the sourcelink package.

It generates a pdb that directs the debugger to the correct version of the file from your VCS provider (e.g. GitHub, BitBucket).

How to debug a nuget package without WIP features using VS 15.7 and above

It will prompt me for the source file during debugging, despite the nupkg containing debugging symbols+sources it isn't working

Even if the debugging symbols+sources are included in the symbols nuget package, but NuGet itself does not have the ability to parse the symbols nuget package when you debugging this nuget package in the Visual Studio. So Visual Studio still can not find the the source file during debugging. That is the reason why NuGet team publish the symbols package to the SymbolSource server.

See How to debug code in a nuget package created by me for some more details.

Besides, since Currently the NuGet package debugging and symbols experience is not streamlined., it not very easy to debug the nuget package from Visual Studio successfully. Not sure why you do not want to specify for the location of the source file, if you are interested in it, you could use the lightweight solution to debug the nuget package:

Is it possible to host both regular and symbols packages in a NuGet local feed on a network share?

I have been using this method all the time without any other issue, hope this helps you.



Related Topics



Leave a reply



Submit