Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug into my nuget package deployed from TeamCity?

I have put a library that my team uses into a nuget package that is deployed from TeamCity into a network folder. I cannot debug into this code though! SymbolSource is one solution I have read about but I would much rather find some way to have access to the .pdb/source files directly from TeamCity. Does anyone know how to do this?

Edit. When I check 'Include Symbols and Source' in the Nuget Pack build step, TeamCity creates a .Symbol.nupkg in addition to the .nupkg file in the network folder. The .Symbol.nupkg contains the src and the .pdb file.

Edit. I unchecked 'Include Symbols and Source' on TeamCity and added the following to my nuspec file:

  <files>     <file src="..\MyLibrary\bin\release\MyLibrary.dll" target="lib\net40" />     <file src="..\MyLibrary\bin\release\MyLibrary.pdb" target="lib\net40" />     <file src="..\MyLibrary\*.cs" target="src" />     <file src="..\MyLibrary\**\*.cs" target="src" />   </files> 

This added the dll, the pdb, and the source files for my library in the nuget package and didn't generate a .Symbols file which I think is only needed for symbol servers.

like image 707
anthonybell Avatar asked Feb 18 '14 15:02

anthonybell


People also ask

How do I debug my NuGet package?

In order to debug into NuGet package libraries, Visual Studio must be configured to use ProGet as a symbol server. To do this select Debug > Options, from the menu bar, then browse to Debugging > Symbols in the tree menu.

Should I include PDB files in NuGet package?

You shouldn't add pdb files to main nuget package.


2 Answers

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

like image 68
Graham Avatar answered Oct 09 '22 09:10

Graham


The latest version of dotPeek (free!) can act as a symbol server and generate pdb files on the fly. This has allowed me to debug into the dlls that are served via teamcity.

Download it here:

http://blog.jetbrains.com/dotnet/2014/04/09/introducing-dotpeek-1-2-early-access-program/

Instructions on how to set it up here.

https://web.archive.org/web/20160220163146/http://confluence.jetbrains.com/display/NETCOM/dotPeek+Symbol+Server+and+PDB+Generation

like image 38
anthonybell Avatar answered Oct 09 '22 09:10

anthonybell