[Mono-list] Detecting mono version
Robert Jordan
robertj at gmx.net
Sun Feb 24 08:41:52 EST 2008
Hi,
Erik Renes wrote:
> Is there any 'supported' way to detect the mono version? Or another way to
> achieve my goal of graceful degredation?
>
> My current code (proof of concept):
> Type t = Type.GetType("Mono.Runtime");
> MethodInfo mi = t.GetMethod("GetDisplayName", BindingFlags.NonPublic |
> BindingFlags.Static );
> string s = (string)mi.Invoke(null, null);
> if (mi!= null)
> Console.WriteLine(s);
It is not recommended to parse the output of GetDisplayName as it
might change in future. Its output is intended to be used
unparsed in bug reports (or for similar purposes).
The best way to detect a specific version *at runtime*
is calling a method that used to throw NotImplementedException
on earlier monos.
If you wonder why there is no reliable version check: it's
not necessary if the application is distributed the Linux
way (rpm, deb): you can add a dependency for the required
mono version.
If your application is distributed in source, you could
add a pkg-config check to its build script:
pkg-config --atleast-version=1.2.4 mono
Robert
More information about the Mono-list
mailing list