Get current app's build version - Xamarin.Android

With a Dependency service:

For iOS:

using Foundation;

[assembly: Xamarin.Forms.Dependency(typeof(Screen_iOS))]

namespace XXX.iOS
{
    public class Screen_iOS : IScreen
    {

        public string Version
        {
            get
            {
                NSObject ver = NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"];
                return ver.ToString();
            }
        }

    }
}

For Android:

using Xamarin.Forms;

[assembly: Dependency(typeof(ScreenAndroid))]

namespace XXX.Droid
{
    class ScreenAndroid : Java.Lang.Object, IScreen
    {

        public string Version
        {
            get
            {
                var context = Forms.Context;
                return context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName;
            }
        }

    }
}

And the interface:

interface IScreen
{
    string Version { get; }
}

For version name:

Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionName

For version code:

Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionCode

In Xamarin.Essentials you can use the following:

Version version = AppInfo.Version;

From there you can get the build version.

If you really just want the build number you can also use the shortcut:

string buildNumber = AppInfo.BuildString;