HOWTO: Debug Visual Studio assemblies with .NET Reflector. Author:Carlos J. Quintero (Microsoft
来源:互联网 发布:好用的男士爽肤水 知乎 编辑:程序博客网 时间:2024/06/05 10:15
https://www.mztools.com/articles/2012/MZ2012023.aspx
Author:Carlos J. Quintero (Microsoft MVP)Applies to:Microsoft Visual Studio 2005Date:September 2012 Microsoft Visual Studio 2008 Microsoft Visual Studio 2010 Microsoft Visual Studio 2012Introduction
This article explains how to debug Visual Studio assemblies (source code not available) using the .NET Reflector commercial tool (http://www.reflector.net/) to diagnose problems with Visual Studio extensions (add-ins, packages, etc.).
The requirements are the following:
- An edition of .NET Reflector that allows to set breakpoints in code (F9), even if you don't have the source. At the time of this writing (version 7.6.1), only the VSPro edition allows this (the VS and Standard edition don't).
- Visual Studio 2010 or 2012 as the debugger IDE, since the .NET Reflector package only integrates with these versions (Visual Studio 2005 or 2008 don't).
In the example provided, the installation of an extension through the Extension Manager of Visual Studio 2010 will be debugged using Visual Studio 2012. The steps are the following:
- In the debugger IDE (Visual Studio 2012), show the .NET Reflector Object Browser toolwindow (".NET Reflector", "Show .NET Reflector Object Browser" menu). For this example we will use Visual Studio 2012.
- Create a Class Library project.
- Save the solution (so that the .NET Reflector Object Browser shows the references of the project, it doesn't show them with temporary solutions).
- In the Project properties window, "Debug" section, select the "Start external program" radiobutton and select the Visual Studio 2010 IDE: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.
- In the Solution Explorer, add a reference to the Visual Studio assembly that you want to Debug. While the folder "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE" contains Visual Studio assemblies (and the "PrivateAssemblies" and "PublicAssemblies" subfolders), Visual Studio actually uses the assemblies that are stored in the Global Assembly Cache (GAC):
- For Visual Studio versions using the CLR 2.0 (Visual Studio 2005 and 2008), the GAC is the folder C:\Windows\Assembly. Since this folder has a shell extension, to reference assemblies in this folder see the article HOWTO: Reference a Visual Studio assembly in the GAC from an add-in.
- For Visual Studio versions using the CLR 4.0 (Visual Studio 2010) or CLR 4.5 (Visual Studio 2012), the GAC is the folder C:\Windows\Microsoft.NET\assembly, which is browsable directly with the Windows Explorer. For this example, select the assembly Microsoft.VisualStudio.ExtensionManager.Implementation.dll (in the folder C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.ExtensionManager.Implementation\v4.0_10.0.0.0__b03f5f7f11d50a3a\) that implements the Extension Manager of Visual Studio 2010.
Note: you can know the actual location of an assembly loaded by Visual Studio using the Process Explorer tool (http://technet.microsoft.com/es-es/sysinternals/bb896653.aspx), locating the devenv.exe process, and clicking the "View", "Show Lower Pane" menu and the "View", "Lower Pane", "DLLs" menu. The tooltip on a dll shows its location. - In the .NET Reflector Object Browser, select the Microsoft.VisualStudio.ExtensionManager.Implementation.dll assembly and right-click the "Enable Debugging" context menu. Click the "Done" button when the decompilation is complete.
- In the .NET Reflector Object Browser, expand the Microsoft.VisualStudio.ExtensionManager.Implementation.dll node and go to some method, for example the "Microsoft.VisualStudio.ExtensionManager.UI" namespace, "ExtensionInstallDialog" class, "InstallExtension" method and double-click it to open its source code. Put a breakpoint on that method.
- Repeat the operation with the "Microsoft.VisualStudio.ExtensionManager" namespace, "ExtensionManagerService" class, "InstallWorker" method.
- Click the "Debug", "Start Debugging" menu of Visual Studio to start debugging.
- Visual Studio 2010 should be launched and the breakpoints should show with an exclamation mark during some seconds until the warning disappears, which means that the debugged assembly is loaded and the debugger is attached.
- Go to the "Tools", "Extension Manager..." menu and install your extension. The breakpoints should be hit at some point of the installation process.
Follow @VSExtensibility
Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)
Author:Carlos J. Quintero (Microsoft MVP)Applies to:Microsoft Visual Studio 2005Date:September 2012 Microsoft Visual Studio 2008 Microsoft Visual Studio 2010 Microsoft Visual Studio 2012Introduction
This article explains how to debug Visual Studio assemblies (source code not available) using the .NET Reflector commercial tool (http://www.reflector.net/) to diagnose problems with Visual Studio extensions (add-ins, packages, etc.).
The requirements are the following:
- An edition of .NET Reflector that allows to set breakpoints in code (F9), even if you don't have the source. At the time of this writing (version 7.6.1), only the VSPro edition allows this (the VS and Standard edition don't).
- Visual Studio 2010 or 2012 as the debugger IDE, since the .NET Reflector package only integrates with these versions (Visual Studio 2005 or 2008 don't).
In the example provided, the installation of an extension through the Extension Manager of Visual Studio 2010 will be debugged using Visual Studio 2012. The steps are the following:
- In the debugger IDE (Visual Studio 2012), show the .NET Reflector Object Browser toolwindow (".NET Reflector", "Show .NET Reflector Object Browser" menu). For this example we will use Visual Studio 2012.
- Create a Class Library project.
- Save the solution (so that the .NET Reflector Object Browser shows the references of the project, it doesn't show them with temporary solutions).
- In the Project properties window, "Debug" section, select the "Start external program" radiobutton and select the Visual Studio 2010 IDE: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.
- In the Solution Explorer, add a reference to the Visual Studio assembly that you want to Debug. While the folder "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE" contains Visual Studio assemblies (and the "PrivateAssemblies" and "PublicAssemblies" subfolders), Visual Studio actually uses the assemblies that are stored in the Global Assembly Cache (GAC):
- For Visual Studio versions using the CLR 2.0 (Visual Studio 2005 and 2008), the GAC is the folder C:\Windows\Assembly. Since this folder has a shell extension, to reference assemblies in this folder see the article HOWTO: Reference a Visual Studio assembly in the GAC from an add-in.
- For Visual Studio versions using the CLR 4.0 (Visual Studio 2010) or CLR 4.5 (Visual Studio 2012), the GAC is the folder C:\Windows\Microsoft.NET\assembly, which is browsable directly with the Windows Explorer. For this example, select the assembly Microsoft.VisualStudio.ExtensionManager.Implementation.dll (in the folder C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.ExtensionManager.Implementation\v4.0_10.0.0.0__b03f5f7f11d50a3a\) that implements the Extension Manager of Visual Studio 2010.
Note: you can know the actual location of an assembly loaded by Visual Studio using the Process Explorer tool (http://technet.microsoft.com/es-es/sysinternals/bb896653.aspx), locating the devenv.exe process, and clicking the "View", "Show Lower Pane" menu and the "View", "Lower Pane", "DLLs" menu. The tooltip on a dll shows its location. - In the .NET Reflector Object Browser, select the Microsoft.VisualStudio.ExtensionManager.Implementation.dll assembly and right-click the "Enable Debugging" context menu. Click the "Done" button when the decompilation is complete.
- In the .NET Reflector Object Browser, expand the Microsoft.VisualStudio.ExtensionManager.Implementation.dll node and go to some method, for example the "Microsoft.VisualStudio.ExtensionManager.UI" namespace, "ExtensionInstallDialog" class, "InstallExtension" method and double-click it to open its source code. Put a breakpoint on that method.
- Repeat the operation with the "Microsoft.VisualStudio.ExtensionManager" namespace, "ExtensionManagerService" class, "InstallWorker" method.
- Click the "Debug", "Start Debugging" menu of Visual Studio to start debugging.
- Visual Studio 2010 should be launched and the breakpoints should show with an exclamation mark during some seconds until the warning disappears, which means that the debugged assembly is loaded and the debugger is attached.
- Go to the "Tools", "Extension Manager..." menu and install your extension. The breakpoints should be hit at some point of the installation process.
Follow @VSExtensibility
Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)
- HOWTO: Debug Visual Studio assemblies with .NET Reflector. Author:Carlos J. Quintero (Microsoft
- .NET Reflector Visual Studio Extension
- Reflector: Get the secret inside .NET assemblies.
- Reflector: Get the secret inside .NET assemblies.
- 关于--初试asp.net 2.0 with Microsoft Visual Studio 2005
- Debug VBScript with Visual Studio
- Microsoft Office Development with Visual Studio
- debug with dump at Visual Studio 2005
- 初试asp.net 2.0 with Microsoft Visual Studio 2005(1)
- 初试asp.net 2.0 with Microsoft Visual Studio 2005(2)
- 初试asp.net 2.0 with Microsoft Visual Studio 2005(3)
- 初试asp.net 2.0 with Microsoft Visual Studio 2005(4)
- 初试asp.net 2.0 with Microsoft Visual Studio 2005(5)
- Build a .NET Application on the Oracle Database with Microsoft Visual Studio 2010
- Microsoft Visual J#.NET (JSharp) Version 7.0 Beta 1 out
- 使用 Microsoft Visual j# .NET 中的设计器进行编程
- Microsoft Visual Studio .NET 系统必备
- Microsoft Visual Studio .NET 2005 网站发布
- Java基础--抽象类和接口的区别
- MySQL INSERT插入多字段条件判断,如果不存在则插入
- 网络隧道Tunnel技术
- C语言指针系列
- 友元
- HOWTO: Debug Visual Studio assemblies with .NET Reflector. Author:Carlos J. Quintero (Microsoft
- [vijos1057]盖房子
- js中给函数传参函数时,函数加括号与不加括号的区别
- CodeVS 1018 单词接龙 题解
- tar: Removing leading '/' from member names
- 【链表】判断两个链表是否相交,并求出交点
- 字符设备驱动基础篇5——驱动如何操控硬件(动静态映射操作LED)
- 深入理解Java之线程池
- react-navigation及dva使用(三)