How can I read the WPF version number for publication in code

I want to read and display the version of the WPF application version in popup windows. In the project properties on the publication tab there is a version of the publication, how can I get and display it in WPF windows.

Thanks in advance

+4
source share
4 answers

Add the link to the library System.Deploymentto your project and edit this piece of 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 the comment, you cannot get the publication version during debugging, so I suggest processing InvalidDeploymentException.

+11
source

Assembly.GetExecutingAssembly()

Assembly.GetExecutingAssembly().GetName().Version.ToString();
+19
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); 

Console.WriteLine(version);
+3

using System.Reflection.Assembly.GetEntryAssembly (). GetName (). Version to avoid getting the version from the dll will always have the version from the current "exe".

+1
source

Source: https://habr.com/ru/post/1539186/


All Articles