Is there a way to get all assemblies that depend on a given assembly?
Pseudo:
Assembly a = GetAssembly();
var dependants = a.GetDependants();
Select one or more assemblies in the Assembly Explorer window, right click the selection and choose Show Assembly Dependency Diagram in the context menu . The diagram will include all selected assemblies as well as all assemblies referenced from them. References between assemblies are represented with arrows.
Solution 1Assembly. GetReferencedAssemblies()[^]. Basically you'll construct an Assembly object to represent the DLL you want to get the references of, and then call the GetReferencedAssemblies method and see if any of the entries refer to the specific POS DLL.
C# Assembly is a standard library developed for . NET. Common Language Runtime, CLR, MSIL, Microsoft Intermediate Language, Just In Time Compilers, JIT, Framework Class Library, FCL, Common Language Specification, CLS, Common Type System, CTS, Garbage Collector, GC.
If you wish to find the dependent assemblies from the current application domain, you could use something like the GetDependentAssemblies
function defined below:
private IEnumerable<Assembly> GetDependentAssemblies(Assembly analyzedAssembly)
{
return AppDomain.CurrentDomain.GetAssemblies()
.Where(a => GetNamesOfAssembliesReferencedBy(a)
.Contains(analyzedAssembly.FullName));
}
public IEnumerable<string> GetNamesOfAssembliesReferencedBy(Assembly assembly)
{
return assembly.GetReferencedAssemblies()
.Select(assemblyName => assemblyName.FullName);
}
The analyzedAssembly
parameter represents the assembly for which you want to find all the dependents.
Programatically, you can use Mono.Cecil to do this.
Something like this (note this won't work if the debugger is attached - e.g. if you run it from inside VS itself):
public static IEnumerable<string> GetDependentAssembly(string assemblyFilePath)
{
//On my box, once I'd installed Mono, Mono.Cecil could be found at:
//C:\Program Files (x86)\Mono-2.10.8\lib\mono\gac\Mono.Cecil\0.9.4.0__0738eb9f132ed756\Mono.Cecil.dll
var assembly = AssemblyDefinition.ReadAssembly(assemblyFilePath);
return assembly.MainModule.AssemblyReferences.Select(reference => reference.FullName);
}
If you don't need to do this programatically, then NDepend or Reflector can give you this information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With