-
Add an assembly reference to
System.Deploymentto your project. -
Import the namespace in your class file:
VB.NET:
Imports System.Deployment.ApplicationC#:
using System.Deployment.Application; -
Retrieve the ClickOnce version from the
CurrentVersionproperty.You can obtain the current version from the
ApplicationDeployment.CurrentDeployment.CurrentVersionproperty. This returns aSystem.Versionobject.Note (from MSDN):
CurrentVersionwill differ fromUpdatedVersionif a new update has
been installed but you have not yet calledRestart. If the deployment
manifest is configured to perform automatic updates, you can compare
these two values to determine if you should restart the application.NOTE: The
CurrentDeploymentstatic property is only valid when the application has been deployed with ClickOnce. Therefore before you access this property, you should check theApplicationDeployment.IsNetworkDeployedproperty first. It will always return a false in the debug environment.VB.NET:
Dim myVersion as Version If ApplicationDeployment.IsNetworkDeployed Then myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion End IfC#:
Version myVersion; if (ApplicationDeployment.IsNetworkDeployed) myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion; -
Use the
Versionobject:From here on you can use the version information in a label, say on an “About” form, in this way:
VB.NET:
versionLabel.Text = String.Concat("ClickOnce published Version: v", myVersion)C#:
versionLabel.Text = string.Concat("ClickOnce published Version: v", myVersion);(
Versionobjects are formatted as a four-part number (major.minor.build.revision).)