Get Assembly version on windows phone 7

前端 未结 4 650
北恋
北恋 2021-02-13 23:56

In my c# applications I usually get the version (to show the customer) using the following code:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Vers         


        
相关标签:
4条回答
  • 2021-02-14 00:45

    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<AssemblyFileVersionAttribute>()
                .First()
                .Version;
    
            return Version.Parse(versionString);
        }
    }
    
    0 讨论(0)
  • 2021-02-14 00:45
     public static string GetVersion()
        {
            return Regex.Match(Assembly.GetExecutingAssembly().FullName, @"Version=(?<version>[\d\.]*)").Groups["version"].Value;
        }
    

    is fairly clean as well.

    0 讨论(0)
  • 2021-02-14 00:51

    Does parsing it out of

    Assembly.GetExecutingAssembly().FullName

    work for you?

    example output: SomeApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    edit: don't need to go through ManifestModule

    0 讨论(0)
  • 2021-02-14 00:52

    Try this:

        private static string GetVersionNumber()
        {
            var asm = Assembly.GetExecutingAssembly();
            var parts = asm.FullName.Split(',');
            return parts[1].Split('=')[1];
        }
    
    0 讨论(0)
提交回复
热议问题