How to detect Windows Phone 8.1 OS version programmatically?

Universal/WinRT apps only work in wp 8.1, so the OS version can only be 8.1. When they make wp8.2 or wp9, they'll probably add a way to check what OS version is installed...

If you're looking for the firmware version, you can get it with:

    Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
    var firmwareVersion = deviceInfo.SystemFirmwareVersion;

Copied from duped question:

Windows Phone 8.1 Silverlight apps can use the .NET version APIs. There is no supported mechanism to get a version number in Universal 8.1 apps, but you can try using reflection to get the Windows 10 AnalyticsInfo class, which will at least tell you the version number if you are running on Windows 10.

Note: Checking the OS version is almost always the wrong thing to do, unless you're simply displaying it to the user (eg, in an "About" box) or sending it to your back-end analytics server for number crunching. It should not be used to make any run-time decisions, because in general it's a poor proxy for whatever-you're-actually-trying-to-do.

Here is a sample:

var analyticsInfoType = Type.GetType(
  "Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime");
var versionInfoType = Type.GetType(
  "Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime");
if (analyticsInfoType == null || versionInfoType == null)
{
  Debug.WriteLine("Apparently you are not on Windows 10");
  return;
}

var versionInfoProperty = analyticsInfoType.GetRuntimeProperty("VersionInfo");
object versionInfo = versionInfoProperty.GetValue(null);
var versionProperty = versionInfoType.GetRuntimeProperty("DeviceFamilyVersion");
object familyVersion = versionProperty.GetValue(versionInfo);

long versionBytes;
if (!long.TryParse(familyVersion.ToString(), out versionBytes))
{
  Debug.WriteLine("Can't parse version number");
  return;
}

Version uapVersion = new Version((ushort)(versionBytes >> 48),
  (ushort)(versionBytes >> 32),
  (ushort)(versionBytes >> 16),
  (ushort)(versionBytes));

Debug.WriteLine("UAP Version is " + uapVersion);

Obviously you can update this to return the version etc. rather than print it to the debug console.