I started with Reflector, but it doesn’t have a simple API needed to generate the files programmatically.
I came across JustDecompile from Telerik and found that they do have a command line API that works great. I could have just invoked the EXE with Process.Start, but I figured I should see how they are doing and see if I could do everything inproc. So I decompiled the JustDecompile.exe file and found a very simple DLL method that they use to output C# files.
1) Download JustDecompile
2) Open up your project and Add References to these two DLLs.
C:\Program Files (x86)\Telerik\JustDecompile\Libraries\JustDecompile.Tools.MSBuildProjectBuilder.dll
C:\Program Files (x86)\Telerik\JustDecompile\Libraries\JustDecompiler.dll
3) Add these namespaces:
using JustDecompile.Tools.MSBuildProjectBuilder;
using Telerik.JustDecompiler.Languages.CSharp;
using System.Threading;
4) Add this code to your project where you want to programmatically decompile code
MSBuildProjectBuilder projectBuilder = new MSBuildProjectBuilder(dll, outfolder, new CSharpV4());
projectBuilder.ProjectFileCreated += new EventHandler<ProjectFileCreatedEvent>(projectBuilder_ProjectFileCreated);
projectBuilder.BuildProject(new CancellationToken());
Read more: Jon Gallant's Blog
QR: