Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding which of a set of assemblies depends on assembly X

Tags:

.net

How can I quickly find, given a folder with .Net assemblies, which of these depends on some given assembly?

(Opening them up one by one with Reflector is not what I had in mind)

like image 758
ripper234 Avatar asked Oct 14 '22 07:10

ripper234


1 Answers

You can do it in code using GetReferencedAssemblies() method of assembly:

public void GetDependentAssemblies(Assembly assembly)
{
    var assembliesPaths = new[] { 
                                  @"c:\dlls\assembly1.dll",
                                  @"c:\dlls\assembly2.dll"
                                };

    IEnumerable<Assembly> dependantAssemblies = assembliesPaths
        .Select(path => Assembly.ReflectionOnlyLoadFrom(path))
        .Where(folderAssembly =>
                   {
                       var fullNames =  folderAssembly.GetReferencedAssemblies()
                                                  .Select(name => name.FullName);
                       return fullNames.Contains(assembly.GetName().FullName);
                   });
}
like image 144
Elisha Avatar answered Oct 18 '22 12:10

Elisha