利用.NET Framework4.0的源代码调试你的应用程序

  .NET Framework 的部分源代码是开源的。这些源代码可以供我们学习和参考。也可在也平时调试应用,直接跳入这些开源了的.NET Framework的代码中。这样既可以学习MS放出来的代码,又可以帮助自己调试。下面我用一个WPF的简单的例子演示一下。

    新建一个WPF应用程序,拖一个button,后台代码弹出一个messagebox就行了。

private void button1_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("hello word");
}

下面我将调试MessageBox.Show("hello word");这个函数中,看图:

利用.NET Framework4.0的源代码调试你的应用程序

按F11,进入MessgeBox类中。

利用.NET Framework4.0的源代码调试你的应用程序

再按F11,进入IsValidMessageBoxButton方法中:

利用.NET Framework4.0的源代码调试你的应用程序

这样你就能看到平时你看不到的代码。

下面这些命名空间的代码是可以调试进去的:

system.activities.core.presentation 
system.activities.durableinstancing 
system.activities 
system.activities.presentation 
system.addin.contract 
system.addin 
system.configuration 
system.core 
system.data.datasetextensions 
system.data.entity.design 
system.data.entity 
system.data.linq 
system.data 
system.data.services.client 
system.data.services.design 
system.data.services 
system.data.sqlxml 
system.drawing 
system.identitymodel 
system.identitymodel.selectors 
system.io.log 
system.management 
system.messaging 
system.net 
system 
system.printing 
system.runtime.durableinstancing 
system.runtime.remoting 
system.runtime.serialization 
system.security 
system.servicemodel.activation 
system.servicemodel.activities 
system.servicemodel.channels 
system.servicemodel.discovery 
system.servicemodel.routing 
system.servicemodel.washosting 
system.servicemodel.web 
system.transactions 
system.web.dynamicdata 
system.web.entity.design 
system.web.entity 
system.web.extensions 
system.web.mobile 
system.web 
system.web.routing 
system.web.services 
system.windows.forms 
system.workflow.activities 
system.workflow.componentmodel 
system.workflow.runtime 
system.workflowservices 
system.xaml.hosting 
system.xml.linq 
system.xml

下面叙述一下如何配置Visual Studio 2010实现这样的调试功能。

首先,到http://referencesource.microsoft.com/netframework.aspx上下面代码包,选择下图的倒数第二个文件下载:

利用.NET Framework4.0的源代码调试你的应用程序

然后,安装在一个你可以读写的目录下面,我是安装在D:\RefSrc。

最后,配置Visual Studio 2010。

1、Tools- Option – Debugging-General,按照下图修改我框起来的地方。

利用.NET Framework4.0的源代码调试你的应用程序

2、Tools- Option – Debugging-Symbols,按照下图进行配置:

利用.NET Framework4.0的源代码调试你的应用程序

总结:这个还不错吧。这样一来就可以在平时调试的时候参考和学习.NET Framework4.0的源代码了。也可以更加的方便找出你程序的问题。




本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2010/07/26/debug-use-net-framework-4-0-source.html,如需转载请自行联系原作者