How to determine the latest version number of a GAC assembly

4.3k views Asked by At

I'm 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, there are two versions of the same assembly in the GAC: foo.dll version 1.0.0.0 and foo.dll version 2.0.0.0. I need a function like the following:

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

Anyone know the best way to do this?

Thanks!

2

There are 2 answers

1
Foxfire On BEST ANSWER

Easiest is:

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

which will automatically give you the latest-version assembly from the GAC.

Please note that the Method is deprecated for good reasons. Asking for an unspecific version from the GAC is going to possibly cause lots of trouble.

Without really knowing what you want to do it's hard to give further advice, but in general if you are looking for a specific version you should rather probe for it instead of just loading "something".

1
Darin Dimitrov On

Using a managed wrapper around the Fusion API (fusion.dll) you could enumerate the assemblies in the GAC, filter them by name and order by version.