How to debug code in the nuget package I created

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

I tried to reference the package solution, but it does not work.

I am using Visual Studio 2013.

+15
source share
5 answers

To debug any DLL you need a symbol file (.pdb). If you create a project in the debug configuration, you will see that these files are generated and placed in the assembly output folder.

Visual studio downloads these symbol files from various places, as described here . But an easy way to debug your nuget packages is to put the .pdb files from the packages in the output folder of the project build you want to debug.


If the code you are trying to debug is classified as a non-user code, you need to uncheck Just My Code in the debugging options.

enter image description here

User and non-user code

To distinguish user code from non-user code, Just My Code searches for character files (.pdb) and program optimizations. The debugger considers the code as non-user code when the binary file is optimized or when the .pdb file is not available.

Three attributes also affect what the debugger considers My code:

  • DebuggerNonUserCodeAttribute tells the debugger that the code to which it is applied is not My code.
  • DebuggerHiddenAttribute hides the code from the debugger, even if Just My Code is disabled.
  • DebuggerStepThroughAttribute tells the debugger to execute the code to which it is applied, and not to enter the code.

All other codes are considered a user code.

+16
source

How to debug code in the nuget package I created

Just as NtFreX replied: "To debug any DLL you need the symbol file of this file (.pdb).". This way you can create character packages that allow consumers to enter your package code in the Visual Studio debugger.

The way we do it (and it works):

  1. Create "* .symbols.nupkg".
  2. Deploy the symbol pack on the SymbolSource server.
  3. Set up an IDE. Package consumers can add https://nuget.smbsrc.net/ to symbol sources in Visual Studio.
  4. Add the required library to the project using NuGet (from our SymbolSource server).
  5. Debug.

For more information, you can refer to Creating character packages .

If these packages are not suitable for publication in the NuGet / SymbolSource gallery, you can place the * .nupkg and * .symbols.nupkg files on the local disk.

Note. Add the source code to the debug source files for the solution that references the package (right-click the Solution, select Properties ... General Properties ... Debug source files and add the root source directory for the corresponding binary link).

+6
source

I got this working by building a project for the nuget package created in debug mode, and then simply copying pdb and dll from the debug directory to the location of the Nuget library inside the project in which I wanted to debug it.

e.g. copy from

ExternalNugetPackage \ Bin \ Debug \

in

ProjectDirectory \ Packages \ ExternalNugetPackage.1.0.0 \ Lib \ NET4.5

+3
source

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

1) Include the full debugging information in the * .csproj file:

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

or right-click on the project properties, assembly, advanced settings, display debugging information - set to full.

2) To enable automatic source code loading and step-by-step execution for your nuget dll package, add the SourceLink.Create.CommandLine package to your project or manually add it to the * .csproj file:

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

More info here

3) In the tools - parameters - debugging, turn off "Include only my code" and enable "Suppress JIT optimization when loading a module (only for managed)."

After that, you can switch to methods from your nuget dll package.

+2
source

Source: https://habr.com/ru/post/1268703/


All Articles