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

17,732

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
Share:
17,732
John Assymptoth
Author by

John Assymptoth

Updated on July 01, 2022

Comments

  • John Assymptoth
    John Assymptoth almost 2 years

    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.

  • Nyerguds
    Nyerguds over 3 years
    "Actually, none of these answers are right" - Admitted, you expanded a lot on the details, but one of the original answers from 2012 does mention dotPeek. Anyway, these kind of questions are generally considered off-topic nowadays since anything asking for the best tool to use is bound to just get answered with people's personal opinions.
  • KUTlime
    KUTlime over 3 years
    I consider the fact that"opinion based" questions are actively forced away from SO like one of the biggest downfall of SO. With more and more years in IT, I consider opinion of more experience guys as one of the best resources. Yeah, there is a lot of trolls out there but there is kind and smart people too. 🤷🏿‍♀️
  • t9mike
    t9mike about 3 years
    ILSpy now supports multi-DLL decompile to C# code with their stand-alone GUI. It even creates an sln file. github.com/icsharpcode/ILSpy