System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
will provide you with the version of the assembly that exists in the AssemblyInfo.cs file, to get the publication version installed in the publication dialog, you should use
System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion
But note that you need to add a link to System.Deployment, and it will work only after publishing your application, by right-clicking on the project file and clicking on the publication, each time you publish it will increase the version.
If you tried to call the above line in debug mode, this will not work and will throw an exception, so you can use the following code:
try { return System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion; } catch(Exception ex) { return Assembly.GetExecutingAssembly().GetName().Version; }
source share