I have a windows forms application that is deployed to two different locations.
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?
ClickOnce is a deployment technology that enables you to create self-updating Windows-based applications that can be installed and run with minimal user interaction.
With a project selected in Solution Explorer, on the Project menu, click Properties. Click the Publish tab. Click the Updates button to open the Application Updates dialog box. In the Application Updates dialog box, make sure that the check box The application should check for updates is selected.
Add an assembly reference to System.Deployment
to your project.
Import the namespace in your class file:
VB.NET:
Imports System.Deployment.Application
C#:
using System.Deployment.Application;
Retrieve the ClickOnce version from the CurrentVersion
property.
You can obtain the current version from the ApplicationDeployment.CurrentDeployment.CurrentVersion
property. This returns a System.Version
object.
Note (from MSDN):
CurrentVersion
will differ fromUpdatedVersion
if 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 CurrentDeployment
static property is only valid when the application has been deployed with ClickOnce. Therefore before you access this property, you should check the ApplicationDeployment.IsNetworkDeployed
property 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 If
C#:
Version myVersion; if (ApplicationDeployment.IsNetworkDeployed) myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
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:
versionLabel.Text = String.Concat("ClickOnce published Version: v", myVersion)
C#:
versionLabel.Text = string.Concat("ClickOnce published Version: v", myVersion);
(Version
objects are formatted as a four-part number (major.minor.build.revision).)
No I do not believe that there is a way. I believe the ClickOnce information comes from the manifest which will only be available in a ClickOnce deployment. I think that hard coding the version number is your best option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With