简体   繁体   English

调试 Nuget 库

[英]Debug Nuget Library

I have a set of Nuget Libraries that I compile and modify myself.我有一组我自己编译和修改的 Nuget 库。

I build them without publishing on any Nuget server.我构建它们而没有在任何 Nuget 服务器上发布。 ( It is not my library ) 这不是我的图书馆

On the other side, I have a project that use such Nugets, but I wish to debug them...另一方面,我有一个使用此类 Nuget 的项目,但我希望对其进行调试...

In the best situation I wish to:在最好的情况下,我希望:

  • use my local .dll and .pdb使用我的本地 .dll 和 .pdb
  • debug by using local .pdb and (updated) source code使用本地 .pdb 和(更新的)源代码进行调试

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?也许我必须在我自己的本地 Nuget 服务器上构建并使用本地 Symbol 服务器,但它看起来有点矫枉过正?

Maybe I have to build on my own local Nuget server and use a local Symbol server too, but it looks overkill?也许我必须在我自己的本地 Nuget 服务器上构建并使用本地 Symbol 服务器,但它看起来有点矫枉过正?

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.据我所知,当你想在新项目中调试nuget库时,你必须在新项目中添加所需的nuget.pdb和相关的xxx.cs源文件。

According to your description, the nuget package is created by yourself which is more easiler to realize it:根据你的描述,nuget包是你自己创建的,更容易实现:

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. 1)如果本地有nuget.pdb文件和对应的cs文件,只要把PDB文件放在引用nuget的项目的输出文件中,然后右键解决方案--> Properties --> Common Properties --> Debug Source Files --> 将cs文件所在的文件夹路径添加到其中。

在此处输入图片说明

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. 2)如果您没有当前nuget.pdb文件及有关CS源文件在本地调试,你需要在这些文件nuget.nupkg通过创建NuGet包时nuget.exe CLI与xxx.nuspec ,以便在安装 nuget 包时可以将这些文件添加到当前代理。

**Note:**This is the special steps for creating your nuget package: **注意:**这是创建 nuget 包的特殊步骤:

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. A)请确保您已下载nuget.exe,然后将其路径设置为环境变量,以便在CMD 中调用。 You can refer to this .你可以参考这个

B) Open CMD, type cd xxxxxx(the path of the project which contains xxxx.csproj ) B)打开 CMD,输入 cd xxxxxx(包含xxxx.csproj的项目路径)

C) type nuget spec to generate the xxx.spec file C)输入nuget spec生成xxx.spec文件

在此处输入图片说明

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. D)然后键入nuget pack以生成包含这些调试文件的 nuget 包。

E) when you install this nuget package in a new project, please do not forget to clean the nuget cache first. E)当您在新项目中安装此 nuget 包时,请不要忘记先清理 nuget 缓存 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 )之后,您应该将资源文件的路径添加到Debug Source Files 。(资源文件存在于C:\\Users\\xxx\\.nuget\\packages\\package name\\srcC:\\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 . F)当您开始调试它时,请不要忘记在Tools禁用Just My Code --> Options --> Debugging --> General --> 取消选中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.此外,您可以将源链接视为源控制,这样您就不会通过 Solution=>properties 配置源路径。

In addition , you can refer to this similar issue .另外,你可以参考这个类似的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM