天天看点

C# 获取程序的三种版本

public static class MainFileVersion
    { 
        public static Version AssemblyVersion
        {
            get { return ((Assembly.GetEntryAssembly()).GetName()).Version; }
        } 

        public static Version AssemblyFileVersion
        {
            get { return new Version(FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).FileVersion); }
        }

        public static string AssemblyInformationalVersion
        {
            get { return FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductVersion; }
        }
    }           

说明:

AssemblyVersion 程序集的版本例如 1.0.0.0 或 1.0.*

AssemblyFileVersion 程序文件版本在文件属性中可以开到 例如 1.0.0.0

AssemblyInformationalVersion 程序文件产品版本,格式可以自己定义例如 V1.0 Alpha