How to get the current product version in C#?

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

My code:

VersionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

I am getting VersionNumber=1.0.0.0, but the current version is 1.0.0.12.


Solution 1:

There are three versions: assembly, file, and product. To get the product version:

using System.Reflection;
using System.Diagnostics;
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fileVersionInfo.ProductVersion;

Solution 2:

I got the answer to my question its Just give the reference to System.Deployment.Application and though it wont work in developement of the visual studio but it will work once the application is deployed.

//using System.Deployment.Application;
//using System.Reflection;
public string CurrentVersion
{
    get
    {
        return ApplicationDeployment.IsNetworkDeployed
               ? ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()
               : Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }
} 

Solution 3:

System.Reflection.Assembly.GetEntryAssembly().GetName().Version