4
votes

I am trying to get a list of referenced assemblies for a an assembly I load into a main app in MEF.

I want to make sure that all the referenced assemblies are present in the folder before running the plugin.

I tried using

List<AssemblyName> a = Assembly.GetEntryAssembly().GetReferencedAssemblies().ToList();

But when I do this, it only shows me assemblies used/loaded at that stage. I want a complete list (at runtime) of assemblies referenced (a replica of the References Folder in VS) regardless of whether they are used at that moment or at all.

2

2 Answers

2
votes

Before loading the plugin, you can load it for reflection only that will load only the metadata of the file. For example:

    var assm = Assembly.ReflectionOnlyLoadFrom(@"Same.dll");
    var reff = assm.GetReferencedAssemblies();

Keep in mind that the associated library can have their references.

1
votes

You can extract that information from the file metadata. Quickest way is probably to use one of the libraries out there to do so.

For example you can use Mono.Cecil

Like this:

var md = ModuleDefinition.ReadModule(assemblyPath);
foreach (var reference in md.AssemblyReferences)
{

}