Thursday 26 December 2013

Source code structure regeneration from .NET assembly

Have you ever run into a scenario where you are presented with an assembly from Production or UAT environment for analysis and also told that this assembly has been present on Production since the time our company had its website launched and the vendor who created the application to us forgot to give us the code for that? I have run into this kind of scenario and i know for sure that some of my colleagues and friends have run into similar situations too.

Of course, we have the option of (hoping that they are not out of business by now) going through the ledgers and bills to find out the work order details, find their current email address and phone number and contact them for the code base. Chances are that they have shown little interest in retaining the code base of what they did 10 years ago. 

Well, the assemblies in question are .NET assemblies you have few more options - use a tool to regenerate the code from the assembly. 

Reflector used to one of the best free .NET tools available but it no longer available as free.

DotPeek is another free tool available that has pretty much all the functionality that is required to regenerate the code. One of the cool features is that it allows to create a project from an assembly and arranges class files in such a way that folder structure follows the namespace hierarchy (goodness that we may need!!) and one file has one class only.

For example : I created simple C# console application, ConsoleApplication1 which only one file Program.cs and it has some classes in different namespaces.


I compiled the application in release mode, added the assembly to dotPeek application and selected the option "Export to Project":


It creates the project which looks like following (notice the nice structure). 


The only sad (if i may say so) part is that it can does not allow generating code for multiple assemblies together.

No comments:

Post a Comment