Aby to zrobić właściwie, trzeba chodzić zespoły , podnosząc zależności ... jeśli twój exe potrzebuje Dll_A, a Dll_A potrzebuje Dll_B (nawet jeśli exe tego nie odwołuje), to twój exe również potrzebuje Dll_B.
Możesz zapytać o to (na dowolnym zestawie) za pomocą odbicia; Wystarczy trochę pracy (zwłaszcza w celu ochrony przed odniesień kołowych, które zdarzają; oto przykład, który rozpoczyna się w „zespole wejściowej”, ale może to równie dobrze być dowolny montaż:
List<string> refs = new List<string>();
Queue<AssemblyName> pending = new Queue<AssemblyName>();
pending.Enqueue(Assembly.GetEntryAssembly().GetName());
while(pending.Count > 0)
{
AssemblyName an = pending.Dequeue();
string s = an.ToString();
if(refs.Contains(s)) continue; // done already
refs.Add(s);
try
{
Assembly asm = Assembly.Load(an);
if(asm != null)
{
foreach(AssemblyName sub in asm.GetReferencedAssemblies())
{
pending.Enqueue(sub);
}
foreach (Type type in asm.GetTypes())
{
foreach (MethodInfo method in type.GetMethods(
BindingFlags.Static | BindingFlags.Public |
BindingFlags.NonPublic))
{
DllImportAttribute attrib = (DllImportAttribute)
Attribute.GetCustomAttribute(method,
typeof(DllImportAttribute));
if (attrib != null && !refs.Contains(attrib.Value))
{
refs.Add(attrib.Value);
}
}
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
refs.Sort();
foreach (string name in refs)
{
Console.WriteLine(name);
}
Jak rozumiem to da te, które już zostały załadowane. Mogą istnieć te, które są przywoływane w metadanych, ale nie zostały jeszcze załadowane, ponieważ nie były potrzebne do tej pory. –
Dzięki za wskazówkę! Ta AppDomain.CurrentDomain.GetAssemblies() była również interesująca – Maciej