Decompiling external source code–Visual Studio
Introduction
There are occasions where one needs to step into 3rd party source code – just to get an idea of what may be going on within their own application (that is using the 3rd party library). Visual Studio does not have a built-in decompilation tool that allows you to do this from within the IDE. Fortunately, there are several tools out there to help you do this – my two favorites are
- ReSharper from JetBrains (free for first 30 days) and
- dotPeek, also from JetBrains (free forever)
ReSharper’s built-in Decompiler
To activate ReSharper’s ‘decompilation’ feature, go into the ReSharper menu –> ‘Options’ and you should see a screen like the one below. Find ‘External Sources’ (meaning 3rd party and other source code), and check the ‘Decompile Methods’ option (after selecting the ‘Navigation to Sources’ radio button).
Using the feature : To use this feature from within Visual Studio, simply right click on the class that you would like to decompile. The right click menu should contain a ‘Navigate To’ option (this is from ReSharper). Select ‘Decompiled Sources’ as shown in the screenshot below:
NOTE: If you still want the old, free versions of Resharper, they can be downloaded here (but they may not contain the decompilation feature. Version 6.0 and above contain the decompiler)
dotPeek (stand alone tool) for Decompilation
dotPeek is a stand-alone windows app that does the same thing as the ReSharper plug-in. As of now, it is completely free. Simply browse to the 3rd party assembly you would like to decompile – and you should see all the classes and method names listed in the left pane. Now, right click on any class – and select ‘Decompiled Sources’. You should see the source code in the right pane.
Summary
There are plenty of other tools (.NET Reflector is one that comes to mind) that do the task of decompilation. ReSharper is standard fare inside most dev teams – and is probably the weapon of choice due to it’s integration with Visual Studio – and its bevy of shortcuts. The only downside is that ReSharper is only free for the first 30 days.
Leave a Reply