How to get app version in Windows Phone?

后端 未结 11 2160
無奈伤痛
無奈伤痛 2020-12-01 13:55

In C# one can use System.Version.Assembly to get the version of a running app. However this doesn\'t appear to exist in Silverlight for Windows Phone. Is there an alternat

11条回答
  •  甜味超标
    2020-12-01 14:31

    First, I think it's more apt to use the assembly's file version info for conveying the application version to the user. See http://techblog.ranjanbanerji.com/post/2008/06/26/Net-Assembly-Vs-File-Versions.aspx

    Second, what about doing this:

    using System;
    using System.Linq;
    using System.Reflection;
    
    public static class AssemblyExtensions
    {
        public static Version GetFileVersion(this Assembly assembly)
        {
            var versionString = assembly.GetCustomAttributes(false)
                .OfType()
                .First()
                .Version;
    
            return Version.Parse(versionString);
        }
    }
    

提交回复
热议问题