How to get the current product version in C#?

前端 未结 9 929
粉色の甜心
粉色の甜心 2020-12-05 01:28

How can I programmatically get the current product version in C#?

My code:

VersionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName         


        
相关标签:
9条回答
  • 2020-12-05 02:26
    System.Reflection.Assembly.GetEntryAssembly().GetName().Version
    
    0 讨论(0)
  • 2020-12-05 02:27

    Try this:

    var thisApp = Assembly.GetExecutingAssembly();
    AssemblyName name = new AssemblyName(thisApp.FullName);
    VersionNumber = "v. " + name.Version;
    

    Also, see this Microsoft Doc on the AssemblyName.Version property.

    0 讨论(0)
  • 2020-12-05 02:28

    Another approach to getting the product version (which is specified using the AssemblyInformationalVersionAttribute) is

    private static string AssemblyProductVersion
    {
        get
        {
            object[] attributes = Assembly.GetExecutingAssembly()
                .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
            return attributes.Length == 0 ?
                "" :
                ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
        }
    }
    
    0 讨论(0)
提交回复
热议问题