如何调试成.NET Framework源代码 [英] How to debug into .NET framework source code

查看:172
本文介绍了如何调试成.NET Framework源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Visual Studio 2017调试.NET框架源代码?

此处有一些关于stackoverflow的问题关于这个话题的知识,但是即使阅读了所有这些知识,我仍然无法使它生效。
我认为提出一个有关如何调试.NET框架源代码的最新有效解决方案将很有用。

我想在不使用任何外部工具(例如dotPeek作为源服务器)的情况下解决该问题。

I would like to solve it without using any external tools (e.g. dotPeek as source server).

推荐答案

首先,我测试了使用 Microsoft Visual Studio Enterprise 2017版本15.9.7 并通过.NET Framework 4.7.2。但是,我认为它应该以相同的方式在Community Edition上起作用。

First of all, I tested it using Microsoft Visual Studio Enterprise 2017, Version 15.9.7 and via .NET Framework 4.7.2. Though, I think it should work on Community edition the same way.

采取的步骤:


  1. 转到工具/选项/调试/常规,然后执行以下设置:

  1. Go to Tools / Options / Debugging / General, and perform these settings:


  • 选中启用.NET Framework源代码步进(这将自动禁用启用我的代码 ;否则,请手动执行)

  • 取消选中要求源文件与原始版本完全匹配

  • 选中启用源服务器支持

  • check Enable .NET Framework source stepping (this will automatically disable "Enable Just My Code"; if not, do it manually)
  • uncheck Require source files to exactly match the original version
  • check Enable source server support

转到工具/选项/调试/符号,然后:

Go to Tools / Options / Debugging / Symbols, and:


  • 在上方列表框中检查 Microsoft Symbol Servers

  • 单击 Empty Symbol Cache (清空符号缓存)按钮(以确保获得正确的符号)

  • 选择加载所有模块(除非排除)底部的单选按钮

  • in the upper listbox check Microsoft Symbol Servers
  • click Empty Symbol Cache button (to make sure you will get the correct symbols)
  • select Load all modules, unless excluded radio button at the bottom

下载.N的源代码您的项目所针对的ET框架版本,来自 https://referencesource.microsoft.com/download.html

Download the source of the .NET framework version your project is targeting, from the https://referencesource.microsoft.com/download.html site.

将下载的存档(zip)文件解压缩到PC上的便捷路径。

Unpack the downloaded archive (zip) file to a convenient path on your PC.

调试您的应用程序;在要调试的.NET代码行中设置一个断点,并使用调试器进入所需的代码行。

Debug your application; set a breakpoint to the line of .NET code you wish to debug, and step to the desired code line with the debugger.

注意:您的应用程序启动可能会变慢,因为它将从互联网下载PDB。

Note: your application may start slower since it will download PDBs from the internet.


  1. 进入(默认为F11)。如果您的设置正确,则会导致一些延迟(如果VS崩溃(如我的崩溃),请再次清空符号缓存)。最终,它将要求提供给定文件的来源,例如 dictionary.cs
    这里可能发生两件事:

  1. Press Step Into (F11 by default). If your settings are correct, this will cause some delay (if your VS crashes (like mine did), Empty Symbol Cache again). Eventually it will ask for the sources of the given file, e.g. dictionary.cs. Two things can happen here:


  • A)它在文件对话框中请求源文件(.cs)。转到第7步。

  • B)提示未找到 whatever.cs ,并且有一个链接显示 浏览并找到任何内容。cs... 。单击该链接。

  • A) It asks for the source file (.cs) in a file dialog. Go to step 7.
  • B) It says whatever.cs not found, and there is a link that says "Browse and find whatever.cs...". Click that link.

在磁盘上选择相应的.cs文件(您可以在操作系统上搜索该文件) 。

Select the corresponding .cs file on your disk (you can search for the file on the OS).

注意:我不得不重新启动VS几次,直到没有崩溃 ,而在寻找资源时,这很可能是VS中的错误。

Note: I had to restart VS several times until it "did not crash" while looking for sources, this is most likely a bug in VS.


  1. 如果您正确执行了所有操作,发现自己正在调试.NET源代码。

注意:由于VS保存了您为源文件,可以停止调试或重新启动VS;下次也可以使用。
此外,您不必必须在框架内手动选择任何其他源文件,因为VS将使用您输入的源文件夹并在其中搜索源文件。

Note: Since VS saves the path you entered for the source files, you can stop debugging or restart VS; it will work next time, too. Besides, you do not have to manually select any more source files within the framework, because the VS will use the source folder you entered and will search in source files there.

这篇关于如何调试成.NET Framework源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆