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

How to debug code in NuGet package created by me(如何调试我创建的 NuGet 包中的代码)
本文介绍了如何调试我创建的 NuGet 包中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个解决方案中创建并安装了一个 NuGet 包,但现在我需要在从我的新解决方案调用时调试包的代码.

我尝试引用包的解决方案,但它不起作用.

我正在使用 Visual Studio 2013.

解决方案

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

Visual Studio 从

以下引用来自 Microsoft - Visual Studio Docs 显示哪些是用户代码,哪些是非用户代码.

<块引用>

用户和非用户代码

为了区分用户代码和非用户代码,Just My Code 查看符号 (.pdb) 文件和程序优化.调试器认为优化二进制文件或 .pdb 时的非用户代码文件不可用.

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

  • DebuggerNonUserCodeAttribute 告诉调试器应用它的代码不是我的代码.
  • DebuggerHiddenAttribute 对调试器隐藏代码,即使 Just My Code 已关闭.
  • 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.

A more detailed answer can be found on my blog.

这篇关于如何调试我创建的 NuGet 包中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)