且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在我创建的NuGet包中调试代码

更新时间:2023-02-16 14:58:19

要调试任何dll,您需要其符号文件(.pdb).如果您在 debug 配置中构建项目,则会看到这些文件已生成并放置在build输出文件夹中.

Visual Studio如

Microsoft-Visual Studio文档显示什么算作用户代码,什么算作非用户代码.

用户和非用户代码

要区分用户代码与非用户代码,请查看我的代码"符号(.pdb)文件和程序优化.调试器认为优化二进制文件或.pdb时,代码将成为非用户代码文件不可用.

三个属性也会影响调试器认为是我的"代码:

  • DebuggerNonUserCodeAttribute告诉调试器它所应用的代码不是我的代码.
  • DebuggerHiddenAttribute从调试器中隐藏代码,即使仅我的代码"已关闭.
  • DebuggerStepThroughAttribute告诉调试器单步执行它所应用的代码,而不是单步执行代码.

所有其他代码均视为用户代码.

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

I tried referencing the solution of the package but it's not working.

I am using Visual Studio 2013.

To debug any dll you need the symbol file of it (.pdb). If you build your project in the debug configuration you will see that those files are generated and put in the build output folder.

Visual studio loads those symbol files from different places as described here. The easiest way to debug your nuget packages is to put the .pdb files of the packages in the build output folder of the project you want to debug.


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

The following quote from the Microsoft - Visual Studio Docs shows what counts as user and what as non-user code.

User and non-user code

To distinguish user code from non-user code, Just My Code looks at symbol (.pdb) files and program optimizations. The debugger considers code to be non-user code when the binary is optimized or when the .pdb file is not available.

Three attributes also affect what the debugger considers to be My Code:

  • DebuggerNonUserCodeAttribute tells the debugger that the code it is applied to is not My Code.
  • DebuggerHiddenAttribute hides the code from the debugger, even if Just My Code is turned off.
  • DebuggerStepThroughAttribute tells the debugger to step through the code it is applied to, rather than step into the code.

All other code is considered to be user code.