Unable to step into Nuget package

2019-07-21 19:19发布

I have a common project that I build and create a nuget package from, for consumption in my other applications.

The build process for the common project both creates a nuget package, deploys it to our private nuget repo and pushes the symbols to our internal symbol server.

In my "other applications", in this specific case an ASP.NET website, I pull in the nuget package from our repo but when I try to step into code in that assembly it just skips over it. I cleared my local symbol cache and as soon as I start debugging VS pulls in all the symbols from the symbol server so I know that bit is working.

Can anyone help me?

enter image description here

1条回答
倾城 Initia
2楼-- · 2019-07-21 20:05

You need to publish Nuget package with symbols and refer to them using the Symbols under Tools->Options->Debugging->Symbols.

See HOW TO DEBUG A .NET CORE NUGET PACKAGE?

Other members also asked the similar issue before:

How to debug code in a nuget package created by me

Update:

Since you want to step into code in the assembly, you still need to provide the source code file in the NuGet package alongside the dll.

As we know:

A symbol is a file containing metadata that represent the link between your original source code and the machine code that has been translated by a compiler.

In the Microsoft world, a symbol is represented by a .PDB (Program DataBase) file. It is the heart of the debugging process because thanks to these metadata, the debugging tools are able to correlate the instructions executing in the application to the original source code and providing features like breakpoint or variable watchers.

So if you only provide the dll and .pdb file, you still not step into the code, you also need provide the source code, then add the source code to the Debug Source Files for the solution that references the package:

More detail on providing the source code:

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 and source file in the src folder. "NuGet spec" may be a useful command for generating the initial spec as defined in NuGet docs. Below is my .nuspec file, you can check it:

<?xml version="1.0"?>
  <package >
    <metadata>
     <id>MyTestPackage</id>
     <version>1.0.3</version>
     <authors>Admin</authors>
     <owners>Admin</owners>
     <requireLicenseAcceptance>false</requireLicenseAcceptance>
     <description>Package description</description>
     <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
     <copyright>Copyright 2017</copyright>
     <tags>Tag1 Tag2</tags>
   </metadata>

   <files>
     <file src="bin\Debug\MyTestPackage.dll" target="lib\Net46" />
     <file src="bin\Debug\MyTestPackage.pdb" target="lib\Net46" />
     <file src="Class1.cs" target="src" />
   </files>
</package>

More detail on add the source code to the Debug Source Files:

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:

enter image description here

Hope this helps.

查看更多
登录 后发表回答