Select Page

When deploying the ClickOnce application to the client, usually there is a requirement to display the application version. It’s possible to hardcode the application version in the configuration file or use the assembly version. But when deploying the ClickOnce application Visual studio can generate publish version and automatically increment revision every time you publish the ClickOnce application. So it’s better to use publish version as the application version. But how to display publish a version in the ClickOnce application if publish version will be available only after publishing is done? It’s very easy with System.Deployment namespace. Below is the C# code to display publish a version in the ClickOnce application.

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) {
    System.Deployment.Application.ApplicationDeployment cd =
    System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
    string publishVersion = cd.CurrentVersion;
    // show publish version in title or About box...
}

System.Deployment.Application namespace is located in System.Deployment.dll which is not referenced by default, so do not forget to add a reference to System.Deployment.dll Also you always have to check IsNetworkDeployed property, because if it’s running locally this property is false and CurrentDeployment will throw an exception.