How can I decompile a batch of .NET DLLs into a Visual Studio project

John Assymptoth picture John Assymptoth · Apr 20, 2012 · Viewed 14.8k times · Source

I just need to search for bits of text in my C# code.

I already have .NET Reflector and the File Disassembler Add-In, but these just seem to decompile one DLL.

Answer

KUTlime picture KUTlime · Oct 24, 2020

Actually, none of these answers are right.

Yeah, all the tools can decompile *.dll files into *.csproj file but none of them supports CLI or batch processing. You can save yourself the time with installations.

The best possible solution so far is use dotPeek, put all *.dll files into one folder and use Explore Folder option.

Explore Folder in dotPeek

dotPeek will analyse the given folder and shows a tree of DLLs located inside the folder. You can generate csproj manually for every single dll which is loaded.

DLL tree


If you came across this post because you are looking answer how locate specific instruction in your or 3rd party dlls, specially a use of reflection, you can use this PowerShell script to decompile dlls into IL and look for the instruction (System.Reflection.Assembly::Load(string) for reflection).

Note

It is using Intermediate Language DisASseMbler (ILDASM) from .NET Framework SDK kit. Adjust the path accordingly to your version of SDK.

function Get-LibDump
{
    Param(
# Specifies a path to one or more locations. Wildcards are permitted.
    [Parameter(Mandatory=$true,
            Position=0,
            ParameterSetName="Basic",
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            HelpMessage="Path to one or more locations.")]
    [ValidateNotNullOrEmpty()]
    [SupportsWildcards()]
    [ValidateScript({$_ | Test-Path})]
    [System.IO.FileInfo]
    $Path
    )
    process
    {
        $dumpFileFilePath = $Path.BaseName + '.il'
        $outFile = "C:\LibDump\$dumpFileFilePath"
        Start-Process -FilePath 'c:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\ildasm.exe' -ArgumentList "/UNICODE /OUT=`"$outFile`" `"$($Path.FullName)`"" -Wait
        "Dump from:`n$(Resolve-Path -Path $Path.FullName -Relative)" | Out-File -FilePath $outFile -Encoding:unicode -Append
    }
}

# Use
Get-ChildItem -Path $PathToLibFolder -Filter '*.dll' -File -Recurse | Get-LibDump