How can I read WPF publish version number in code behind
Access the assembly version using Assembly.GetExecutingAssembly()
and display in UI
Assembly.GetExecutingAssembly().GetName().Version.ToString();
Add reference to System.Deployment
library to your project and adjust this snippet to your code:
using System.Deployment.Application;
and
string version = null;try{ //// get deployment version version = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();}catch (InvalidDeploymentException){ //// you cannot read publish version when app isn't installed //// (e.g. during debug) version = "not installed";}
As stated in comment, you cannot obtain publish version during debug, so I suggest to handle InvalidDeploymentException
.
useSystem.Reflection.Assembly.GetEntryAssembly().GetName().Versionto avoid get version from dll,will get always the version from the current "exe".