Debug Nuget Library

♀尐吖头ヾ 提交于 2020-11-25 03:42:12

问题


I have a set of Nuget Libraries that I compile and modify myself.

I build them without publishing on any Nuget server. (It is not my library)

On the other side, I have a project that use such Nugets, but I wish to debug them...

In the best situation I wish to:

  • use my local .dll and .pdb
  • debug by using local .pdb and (updated) source code

I'm looking for the best possible solution, if possible by loading all local symbols, but I'm not sure it is possible.

Maybe I have to build on my own local Nuget server and use a local Symbol server too, but it looks overkill?


回答1:


Maybe I have to build on my own local Nuget server and use a local Symbol server too, but it looks overkill?

As far as l know, when you want to debug a nuget library in a new project, you must add the required nuget.pdb and related xxx.cs source files in the new project.

According to your description, the nuget package is created by yourself which is more easiler to realize it:

1) If you have the nuget.pdb file and the corresponding cs file on the local, you just need to put the PDB file in the output file of the project which references the nuget, and then right-click on the Solution-->Properties-->Common Properties-->Debug Source Files-->to add the folder path which the cs files exist into it.

2) If you do not have the current nuget.pdb file and related cs source files for debugging on the local, you need to include these files in nuget.nupkg when creating the nuget package by using nuget.exe cli with xxx.nuspec, so that these files can be added to the current agent when you install the nuget package.

**Note:**This is the special steps for creating your nuget package:

A) please make sure that you have downloaded the nuget.exe and then set its path to environment variables so that it can be called in CMD. You can refer to this.

B) Open CMD, type cd xxxxxx(the path of the project which contains xxxx.csproj)

C) type nuget spec to generate the xxx.spec file

Then open it and add like these:

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
   ........
  </metadata>
<files>
<file src="bin\Debug\ClassLibrary11.pdb" target="lib\target framework version (like net472 or netstandard2.0)" />------ClassLibrary11.pdb is the nuget.pdb
 <file src="Class1.cs" target="src" />------Class1.cs is the source file
</files>
</package>

D) then type nuget pack to generate the nuget package which contains these debug files.

E) when you install this nuget package in a new project, please do not forget to clean the nuget cache first. After that, you should add the path of the resource files into Debug Source Files.(the resource files exists in the C:\Users\xxx\.nuget\packages\package name\src or C:\xxxxx\ConsoleApp(project folder)\packages\package name\src)

Edit

F) When you start debugging it, please do not forget to disable Just My Code In Tools-->Options-->Debugging-->General-->uncheck Enable Just My Code.

Also, you can consider source links as source control so that you won't configure the source path by Solution=>properties.

In addition, you can refer to this similar issue.



来源:https://stackoverflow.com/questions/60247078/debug-nuget-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!