Accessing application versions
In .NET, an application has a number of different versions and so, we have a number of alternative ways to access them. The version number that we discussed earlier and is displayed in the Publish Version section of the Publish tab of the project properties can be found using the ApplicationDeployment
class from the System.Deployment
DLL.
using System.Deployment.Application; ... private string GetPublishedVersion() { if (ApplicationDeployment.IsNetworkDeployed) { return ApplicationDeployment.CurrentDeployment.CurrentVersion. ToString(); } return "Not network deployed"; }
Note that we need to verify that the application has actually been deployed before we can access the CurrentVersion
property of the ApplicationDeployment
class, otherwise an InvalidDeploymentException
will be thrown. This means that we cannot attain the published version while debugging our WPF applications...