[ACCEPTED]-Determine referenced dll file version in C#-.net
The simplest way is if you know a type in 5 the referenced assembly:
AssemblyName name = typeof(MyCompany.MyLibrary.SomeType).Assembly.GetName();
Assembly.GetName returns an AssemblyName which 4 has a Version property indicating the version of 3 the assembly.
Alternatively, you can get 2 the assembly names of all assemblies referenced 1 by the executing assembly (i.e., the .exe):
AssemblyName names = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
Perhaps the easiest solution is this:
var version = Assembly.GetAssembly(typeof(SomeType)).GetName().Version;
where 9 SomeType is a type you know for sure that 8 is defined in that particular assembly. You 7 can then call .ToString() on this version object or look 6 at its properties.
Of course, this will blow 5 up in a huge fireball the moment you move 4 your type into another assembly. If this 3 is a possibility, you will need a more robust 2 way to find the assembly object. Let me 1 know if this is the case.
AssemblyInfo class has all this information, so 4 you just need to get a reference to the 3 assembly in your code. For example:
You 2 can get the other assemblies in the project 1 in various ways, for example
var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
More Related questions