MichaelS
MichaelS

Reputation: 7103

How to find all assemblies that reference a specific dll?

I've a directory with a large number of dlls. I need to find all those that reference a specific dll.

I'm thinking about the following solution :

  1. Loop the assemblies and invoke each one with ildasm
  2. Dump the manifest into a text file
  3. Search the text files for the required assembly name.

Yet this solution feels immensely wrong to me. Is there a better way to achieve it?

Upvotes: 4

Views: 9601

Answers (4)

Smith
Smith

Reputation: 5951

Download IlSpy.exe, and open the assembly whose references you want to see, it will list all referenced assemblies.

https://github.com/icsharpcode/ILSpy/releases

Upvotes: 0

JLuis Estrada
JLuis Estrada

Reputation: 938

Download AsmSpy.exe, it has the option to list all assemblies and all the references within the assemblies.

https://github.com/mikehadlow/AsmSpy

Upvotes: 0

Yanshof
Yanshof

Reputation: 9926

According to Microsoft documentationnn AppDomain.CurrentDomain.GetAssemblies() Gets the assemblies that have been loaded into the execution context of this application domain. About AppDomain.CurrentDomain.GetAssemblies()

It seems that you need to change strategy of loading the asseblies you need from using the appdomain to looking for dlls in your applications folder.

I found a discuss on similar problem here

Upvotes: 0

Dirk
Dirk

Reputation: 10958

You could write a small tool for that purpose, using Reflection to find the referenced assemblies:

string[] fileNames = ...; // get all the filenames
foreach (string fileName in fileNames) {
    var assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(fileName);
    var referencedAssemblies = assembly.GetReferencedAssemblies();

    foreach (var assemblyName in referencedAssemblies) {
        // do your comparison
    }
}

Upvotes: 13

Related Questions