How to get the current product version in C#?

前端 未结 9 932
粉色の甜心
粉色の甜心 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:05

    All these answers ask for the assembly with .GetExecutingAssembly().
    If you have this code in a dll, it will return the dll version number.

    Swap that call for GetCallingAssembly() to get the place in your code that wanted to know.

    /// 
    /// Returns version like 2.1.15
    /// 
    public static String ProductVersion
    {
        get
        {
            return new Version(FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location).ProductVersion).ToString();
        }
    }
    

提交回复
热议问题