views:

140

answers:

3

I need to iterate a list of assemblies and determine their version numbers. I've made use of System.Reflection.Assembly.GetExecutingAssembly().GetName().Version before, but in this case I'm working with assemblies that have not yet been loaded. I understand I can use System.Reflection.Assembly.ReflectionOnlyLoadFrom("assembly.dll") but I've read that this can eat memory unless I load the assemblies in their own application domain and then unload them. Is this true of ReflectionOnlyLoadFrom() or just LoadFrom()?

Alternatively, is there a way of obtaining the version info without loading the assembly?

+1  A: 

You could use the Cecil-library of the Mono-project.

Tommy Carlier
I like this idea a lot.
grenade
A: 

I think their are no way to get assembly version without loading it.

Nakul Chaudhary
+5  A: 

Take a look at System.Reflection.AssemblyName. You can do

AssemblyName.GetAssemblyName("foo.dll").Version

which returns System.Version object where you can get major, minor, minor revison, and revision information. According to the Msdn article on GetAssemblyName method:

This will work if the file contains an assembly manifest. This method causes the file to be opened and closed, but the assembly is not added to this domain.

Mehmet Aras
Accepted over cecil suggestion as this doesn't introduce dependencies in our environment.
grenade
Be warned, here be dragons! This was working great for us, but as different types of projects (WPF is doing strange things) with different reference requirements, it started misbehaving, and the problems are not easy to track down. I'm moving our code to use Cecil.
Si