Abdulsalam Elsharif Abdulsalam Elsharif - 1 year ago 94
C# Question

How can I read WPF publish version number in code behind

I want to read and display WPF application publish version number in splash windows, In project properties in publish tab there is publish version, how can I get this and display it in WPF windows.

Thanks in advance

Bru Bru
Answer Source

Add reference to System.Deployment library to your project and adjust this snippet to your code:

using System.Deployment.Application;


string version = null;
    //// 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download