How to determine the latest version number of a GAC ​​assembly

I am trying to create a diagnostic log for my application that will display the latest version number of an assembly installed in the GAC. For example, the GAC has two versions of the same assembly: foo.dll version 1.0.0.0 and foo.dll version 2.0.0.0. I need a function similar to the following:

GetLatestGacVersion("foo.dll");  // returns "2.0.0.0"

      

Does anyone know a better way to do this?

Thank!

+2


source to share


2 answers


The easiest way:

Assembly a = Assembly.LoadWithPartialName ("foo.dll");
return a.GetName ().Version

      

which will automatically give you the latest build from the GAC.



Please note that this method is deprecated for good reasons. Asking for a non-specific version of the GAC will probably cause a lot of problems.

Without knowing what you want to do it is difficult to give further advice, but in general, if you are looking for a specific version, you should rather research it rather than just download "something."

+4


source


Using a managed wrapper around Fusion API

(fusion.dll), you can enumerate assemblies in the GAC, filter them by name and order by version.



+3


source







All Articles