![]() |
|
|
|||||||
![]() |
ASP Net - how to find out the version of an assembly? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 Bob |
|
|
|
|
#2 |
|
Posts: n/a
|
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" <> wrote in message news:%... > 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 > > |
|
|
|
#3 |
|
Posts: n/a
|
Thanks a lot for the help John. Exacly what I needed. Bob
"John" <> wrote in message news:wemwc.7257$... > 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" <> wrote in message > news:%... > > 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 > > > > > > |
|
|
|
#4 |
|
Posts: n/a
|
John,
Thanks for the quote =) -- - Nicholas Paldino [.NET/C# MVP] - "John" <> wrote in message news:wemwc.7257$... > 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" <> wrote in message > news:%... > > 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 > > > > > > |
|
|
|
#5 |
|
Posts: n/a
|
>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 |
|
|
|
#6 |
|
Junior Member
Join Date: Sep 2006
Posts: 2
|
if the dll doesn't follow com guidelines how to get the version ,prod version info without loading it using the loadlib function ?
thanks |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Sep 2006
Posts: 2
|
if the dll doesn't follow com guidelines how to get the version ,prod version info without loading it using the loadlib function ?
thanks |
|
|
|