How to read version of assembly programmaticaly?

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!
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
K

Katit

I'm just using assembly. How do I get reference to assembly? I'm using
classes itself. Dumb question, not sure on syntax..

Thanks
 
Z

zacks

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
K

Katit

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?
 
K

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.

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?
 
K

Katit

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
 
M

Mythran

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
 

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