How to read version of assembly programmaticaly?

  • Thread starter Thread starter Katit
  • Start date Start date
K

Katit

I have app that uses DLL's (ours) I need to get version info for those
DLL's
For main EXE I just use "Application.ProductVersion"

How do I get versions of components?

Thanks!
 
Katit,

Assuming you can get an Assembly reference to the assembly you want to
get the version of, you can call the GetName method on the Assembly
instance, which returns an AssemblyName instance to you. From that, you can
use the Version property on the AssemblyName instance to get the version
information for the assembly.
 
I'm just using assembly. How do I get reference to assembly? I'm using
classes itself. Dumb question, not sure on syntax..

Thanks
 
I have app that uses DLL's (ours) I need to get version info for those
DLL's
For main EXE I just use "Application.ProductVersion"

How do I get versions of components?

Thanks!

Add a Property to the DLL for product version, and in the DLL's
constructor, set the value of the property from the
Application.ProductVersion property.
 
Katit,

You will have to call one of the static method on the Assembly class to
get the assembly reference. Something like Load, LoadFrom, etc, etc. If
the assembly is already loaded, then it will return the loaded version.

Also, you can call the GetReferencedAssemblies on an Assembly instance
to get the assemblies that your dll/exe references.
 
Add a Property to the DLL for product version, and in the DLL's
constructor, set the value of the property from the
Application.ProductVersion property.

Then I need to add reference to System.Windows.Forms. Correct?
 
You will have to call one of the static method on the Assembly class to
get the assembly reference. Something like Load, LoadFrom, etc, etc. If
the assembly is already loaded, then it will return the loaded version.

Still don't understand. Should I write it?

Let's say my assembly named KatitAss :)
I have classed A, B and C

What is the syntax to get what I need?
 
Then I need to add reference to System.Windows.Forms. Correct?

I did, and it returns version of main EXE
Where is "constructor" for DLL??

There is classes, I places this property in one of the classes
 
Katit said:
I'm just using assembly. How do I get reference to assembly? I'm using
classes itself. Dumb question, not sure on syntax..

Thanks

// Get the name of a specific class instance.
someInstance.GetType().Assembly.GetName().Version

- or -

// Get the name of the current class instance.
this.GetType().Assembly.GetName().Version

- or -

// Can't remember if this works, but you can try it ;)
typeof(ClassName).Assembly.GetName().Version

HTH,
Mythran
 
Back
Top