how to find out the version of an assembly?

B

Bob

I need to extract the version number of an assembly in my .NET Windows app.
The assembly is not referenced by this Windows app. I think I need to use
reflection but just can't figure out the coding. Could someone help?

Thanks a lot in advance
Bob
 
J

John

Quoting from some answers from other people in these forums:

The GetName method on the Assembly will give you an instance of the
AssemblyName class. That will have a Version property which will return an
Version class instance. Once you have this, you should be able to use the
properties of the class (Build, Major, Minor, Revision) or you can get a
string representation by calling ToString.

(orig post by Nicholas Paldino [.NET/C# MVP] )

And:

************
Code Sample
************
try
{
Assembly a = Assembly.LoadFrom("FTPClient.dll");
Console.WriteLine("Image Runtime Version: {0}", a.FullName);
Debug.WriteLine("Image Runtime Version: " + a.FullName);
}
catch (Exception e)
{
Console.WriteLine("Exception occurred: {0}", e.Message);
}
finally
{
Console.ReadLine();
}

************
Output
************
Image Runtime Version: FTPClient, Version=1.0.1117.28417, Culture=neutral,
PublicKeyToken=null

(orig post by Mike Diehl)

Hope that gives you something to work with. Anyway, good luck!
 
B

Bob

Thanks a lot for the help John. Exacly what I needed. Bob

John said:
Quoting from some answers from other people in these forums:

The GetName method on the Assembly will give you an instance of the
AssemblyName class. That will have a Version property which will return an
Version class instance. Once you have this, you should be able to use the
properties of the class (Build, Major, Minor, Revision) or you can get a
string representation by calling ToString.

(orig post by Nicholas Paldino [.NET/C# MVP] )

And:

************
Code Sample
************
try
{
Assembly a = Assembly.LoadFrom("FTPClient.dll");
Console.WriteLine("Image Runtime Version: {0}", a.FullName);
Debug.WriteLine("Image Runtime Version: " + a.FullName);
}
catch (Exception e)
{
Console.WriteLine("Exception occurred: {0}", e.Message);
}
finally
{
Console.ReadLine();
}

************
Output
************
Image Runtime Version: FTPClient, Version=1.0.1117.28417, Culture=neutral,
PublicKeyToken=null

(orig post by Mike Diehl)

Hope that gives you something to work with. Anyway, good luck!


Bob said:
I need to extract the version number of an assembly in my .NET Windows app.
The assembly is not referenced by this Windows app. I think I need to use
reflection but just can't figure out the coding. Could someone help?

Thanks a lot in advance
Bob
 
N

Nicholas Paldino [.NET/C# MVP]

John,

Thanks for the quote =)


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John said:
Quoting from some answers from other people in these forums:

The GetName method on the Assembly will give you an instance of the
AssemblyName class. That will have a Version property which will return an
Version class instance. Once you have this, you should be able to use the
properties of the class (Build, Major, Minor, Revision) or you can get a
string representation by calling ToString.

(orig post by Nicholas Paldino [.NET/C# MVP] )

And:

************
Code Sample
************
try
{
Assembly a = Assembly.LoadFrom("FTPClient.dll");
Console.WriteLine("Image Runtime Version: {0}", a.FullName);
Debug.WriteLine("Image Runtime Version: " + a.FullName);
}
catch (Exception e)
{
Console.WriteLine("Exception occurred: {0}", e.Message);
}
finally
{
Console.ReadLine();
}

************
Output
************
Image Runtime Version: FTPClient, Version=1.0.1117.28417, Culture=neutral,
PublicKeyToken=null

(orig post by Mike Diehl)

Hope that gives you something to work with. Anyway, good luck!


Bob said:
I need to extract the version number of an assembly in my .NET Windows app.
The assembly is not referenced by this Windows app. I think I need to use
reflection but just can't figure out the coding. Could someone help?

Thanks a lot in advance
Bob
 
M

Marc Scheuner [MVP ADSI]

Quoting from some answers from other people in these forums:
The GetName method on the Assembly will give you an instance of the
AssemblyName class. That will have a Version property which will return an
Version class instance.

If you know the name and location of the assembly, you can also use
the FileVersionInfo class. The benefit is the fact you don't have to
actually LOAD the assembly to get at its file and product version info
(this is especially important since you can't UNLOAD an assembly per
se).

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Joined
Sep 20, 2006
Messages
2
Reaction score
0
this i sfine but what if u can't load the dll ?

if the dll doesn't follow com guidelines how to get the version ,prod version info without loading it using the loadlib function ?

thanks
 
Joined
Sep 20, 2006
Messages
2
Reaction score
0
this is fine but what if u can't load the dll ?

if the dll doesn't follow com guidelines how to get the version ,prod version info without loading it using the loadlib function ?

thanks
 

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

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top