Reputation: 146
I'm trying to build method that will check all dlls that are not system dlls, and download them from FTP. For example I have some devxpress DLLs referenced and newtonsoft (Json.net). Problem is when I try to get list I only get 16 of them and there are more on reference list.
List<string> moduli = new List<string>();
Assembly a = typeof(frmPostavkeDokumenata).Assembly;
Assembly assem =Assembly.GetEntryAssembly();
foreach (AssemblyName an in assem.GetReferencedAssemblies())
{
if (!an.Name.Contains("System") &&
!an.Name.Contains("mscorlib") && !an.Name.Contains("Microsoft"))
{
moduli.Add(an.Name);
}
}
This is my reference list:
Upvotes: 4
Views: 4732
Reputation: 13146
Assembly.GetReferencedAssemblies
just retrieve the referenced assemblies which are used as a Type in your Assembly. So, actually it is impossible to retrieve Visual Studio references using reflection.
This is the only way to perform it that you should parse .csproj file of assembly/project.
Upvotes: 2
Reputation: 101443
When you compile your project in visual studio - only dlls which are actually used by your project will be compiled into dll\exe metadata as referenced assemblies, regardless of which are listed in "references" section.
You have several options:
Recursively build list of referenced assemblies. This will give you a list of all assemblies used by your application and all assemblies used by its dependencies, which should be a complete list of dlls you might actually need at runtime.
Subscribe to AppDomain.AssemblyResolve
event and provide missing dlls there (better option).
Upvotes: 1