I have a windows forms application that is deployed to two different locations.
- Intranet – ClickOnce
- Internet – Installed on a citrix farm through Windows installer
I display ClickOnce version number for click-once deployed versionApplicationDeployment.IsNetworkDeployed
.
if (ApplicationDeployment.IsNetworkDeployed)
return ApplicationDeployment.CurrentDeployment.CurrentVersion;
But for the non-click application, I am not sure how to retrieve clickonce version unless I hardcode the version number in assembly info.
Is there an automatic way of retrieve ClickOnce version number for non-clickonce deployed version?
Best Answer
Add an assembly reference to
System.Deployment
to your project.Import the namespace in your class file:
VB.NET:
C#:
Retrieve the ClickOnce version from the
CurrentVersion
property.You can obtain the current version from the
ApplicationDeployment.CurrentDeployment.CurrentVersion
property. This returns aSystem.Version
object.Note (from MSDN):
NOTE: The
CurrentDeployment
static property is only valid when the application has been deployed with ClickOnce. Therefore before you access this property, you should check theApplicationDeployment.IsNetworkDeployed
property first. It will always return a false in the debug environment.VB.NET:
C#:
Use the
Version
object:From here on you can use the version information in a label, say on an "About" form, in this way:
VB.NET:
C#:
(
Version
objects are formatted as a four-part number (major.minor.build.revision).)