The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[UWP]How to retrieve OS Version in a universal app? RRS feed

  • Question

  • Hi,

    We're using the OSVersion for tracking and debugging in our apps.

    In WP8 Silverlight, we used to get that info using Environment.OSVersion, is there an equivalent on Windows 10 UWP?

    Regards,

    Carl




    • Edited by Carl B. Anderson Wednesday, December 9, 2015 3:34 PM Added reason
    • Edited by Barry Wang Thursday, December 10, 2015 8:41 AM title tag
    Wednesday, December 9, 2015 3:28 PM

Answers

  • Yes you can;

    https://www.suchan.cz/2015/08/uwp-quick-tip-getting-device-os-and-app-info/


    http://pauliom.wordpress.com

    • Proposed as answer by Barry Wang Thursday, December 10, 2015 8:46 AM
    • Marked as answer by Barry Wang Monday, December 21, 2015 8:47 AM
    Wednesday, December 9, 2015 9:25 PM
  • The purpose of AnalyticsInfo.VersionInfo is to provide an opaque version string for telemetry and logs. It should not be used to reconstruct an old-school version number within an app. There are numerous reasons why GetVersion(Ex) and VerifyVersionInfo are not supported for UWP apps.

    The best thing to do is transmit/store the opaque string as is, and then use some server side tool to track back to an old-school 0.0.0.0 style build version if you need it. You should never base a runtime app branch on the VersionInfo string.




    Friday, December 11, 2015 5:35 AM

All replies

  • Hello,

    The following code will help you get OS version:

    string deviceFamilyVersion = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
            ulong version = ulong.Parse(deviceFamilyVersion);
            ulong major = (version & 0xFFFF000000000000L) >> 48;
            ulong minor = (version & 0x0000FFFF00000000L) >> 32;
            ulong build = (version & 0x00000000FFFF0000L) >> 16;
            ulong revision = (version & 0x000000000000FFFFL);
            var osVersion = $"{major}.{minor}.{build}.{revision}";

    Hope this helps!


    • Edited by Lion Pham Wednesday, December 9, 2015 10:19 PM
    Wednesday, December 9, 2015 4:25 PM
  • Yes you can;

    https://www.suchan.cz/2015/08/uwp-quick-tip-getting-device-os-and-app-info/


    http://pauliom.wordpress.com

    • Proposed as answer by Barry Wang Thursday, December 10, 2015 8:46 AM
    • Marked as answer by Barry Wang Monday, December 21, 2015 8:47 AM
    Wednesday, December 9, 2015 9:25 PM
  • The purpose of AnalyticsInfo.VersionInfo is to provide an opaque version string for telemetry and logs. It should not be used to reconstruct an old-school version number within an app. There are numerous reasons why GetVersion(Ex) and VerifyVersionInfo are not supported for UWP apps.

    The best thing to do is transmit/store the opaque string as is, and then use some server side tool to track back to an old-school 0.0.0.0 style build version if you need it. You should never base a runtime app branch on the VersionInfo string.




    Friday, December 11, 2015 5:35 AM
  • Hello,

    The following code will help you get OS version:

    string deviceFamilyVersion = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
            ulong version = ulong.Parse(deviceFamilyVersion);
            ulong major = (version & 0xFFFF000000000000L) >> 48;
            ulong minor = (version & 0x0000FFFF00000000L) >> 32;
            ulong build = (version & 0x00000000FFFF0000L) >> 16;
            ulong revision = (version & 0x000000000000FFFFL);
            var osVersion = $"{major}.{minor}.{build}.{revision}";

    Hope this helps!



    FYI that's pretty poor form to present someone else's solution as your own, you need to at least reference your source

    http://pauliom.wordpress.com

    Friday, December 11, 2015 8:29 AM