How to get the publish version of a WPF application

Raj123 picture Raj123 · Mar 20, 2014 · Viewed 16k times · Source

I want my WPF application publish version. I tried using the answer for this question. It works but the problem is we can manually change the values there. I want to know how many times my project was actually published (don't need version number. Just how many times did I publish my application). Can this be done?

Answer

Sheridan picture Sheridan · Mar 20, 2014

Using Click Once, each time you publish, Visual Studio will change the number automatically. It will increment the value each time you publish. Your problem is that you have manually changed the number. The solution is to publish and just let Visual Studio update the value... you should notice that your project needs to be saved once you have published. This is because Visual Studio just incremented the value for you.


UPDATE >>>

If you want to access the published version from code (which you should have made clear in your question), then you can use this code, but you have to ensure that the application is network deployed first... that means that it has actually been published, so it won't work while you are debugging. Try this:

private string GetPublishedVersion()
{
    if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
    {
        return System.Deployment.Application.ApplicationDeployment.CurrentDeployment.
            CurrentVersion.ToString();
    }
    return "Not network deployed";
}