How do I find out the Xamarin.iOS or Xamarin.Android versions in code?

DavinciumDavincium GBBeta ✭✭
edited November 2015 in Cross Platform with Xamarin

I've found out how to display the mono runtime version and the iOS/Android OS versions.
But what about the version info that's shown when you click About Xamarin Studio / Show Details ?
Xamarin.iOS
Version: 9.1.0.31 (Business Edition)
Xamarin.Android
Version: 5.1.9.0 (Business Edition)

This is how I've got the runtime and OS versions:
Mono.Runtime.GetDisplayName() -> Runtime version
ObjCRuntime.Constants.Version -> iOS Version
Android.OS.Build.VERSION.Release -> Android Version

Answers

  • DavinciumDavincium GBBeta ✭✭
    edited November 2015

    :)

  • GuillaumePerrotGuillaumePerrot USMember ✭✭

    Xamarin.Android: use tip from https://developer.xamarin.com/releases/android/xamarin.android_4/xamarin.android_4.14/

            var attrs = (System.Reflection.AssemblyInformationalVersionAttribute[])
            typeof(Java.Lang.Object)
            .Assembly
            .GetCustomAttributes(typeof(System.Reflection.AssemblyInformationalVersionAttribute), inherit: true);
            string version = attrs[0].InformationalVersion;
    

    Xamarin.iOS: if linker is enabled (typically in release) you have access only to the 3 digits version you already used: ObjCRuntime.Constants.Version

    Full Xamarin.iOS version is available when linker is not used with similar syntax to Android:

            var attrs = (System.Reflection.AssemblyInformationalVersionAttribute[])
                typeof(ObjCRuntime.Constants)
            .Assembly
            .GetCustomAttributes(typeof(System.Reflection.AssemblyInformationalVersionAttribute), inherit: true);
            string version = attrs.Length > 0 ? attrs[0].InformationalVersion : ObjCRuntime.Constants.Version;
    

    This code will get you full string version when available and fail over short version when linker is used on iOS.

Sign In or Register to comment.