Identifying EXE and all DLL versions in an assembly

D

Dave Hall

Can anyone get me started on identifying the version of the EXE and all DLLs
in an assembly. I'm trying to build a class in a DLL that can be included in
any assembly, which will determine all of the DLLs in that assembly, as well
as the EXE, and then provide a tab and newline delimited string with all of
their names and versions. So far, I have been able to determine the version
of the DLL that my code runs in, but not the version of the EXE or any other
DLLs in the application. Here's the code I have so far:

System.Reflection.Assembly thisAssy =
System.Reflection.Assembly.GetExecutingAssembly();
string str = thisAssy.GetName().Name + "\t" +
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString
();
System.Reflection.Module[] modules = thisAssy.GetModules();
foreach(System.Reflection.Module module in modules)
{
// Where do we really get info on all of the DLLs?
str = str + "\n" + module.Name + "\t" +
module.Assembly.GetName().Version.ToString();
}
return str;

Thanks,
Dave
 
A

Alex Feinman [MVP]

The problem is that each of the DLLs and the EXE itself are separate
assemblies. Because of that and the fact that assemblies are not statically
bound, you cannot tell which assemblies are referenced by the particular
assembly. For those assemblies that you write yourself, you can create a
class that would register assembly version with static class instance, so
that later you can generate a list. This will not help you with other people
assemblies. To handle those, you can a) enumerate dlls in the directory
where your executing assembly is and b) specifically check versions of
well-known system assemblies
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top