How to display ClickOnce version number in Windows Forms

I have a windows forms application that deploys in two different places.

  • Intranet - ClickOnce
  • Internet - Installed on a Citrix Farm Through Windows Installer

I show the ClickOnce version number for the deployed version of ApplicationDeployment.IsNetworkDeployed to unlock in different ways.

 if (ApplicationDeployment.IsNetworkDeployed) return ApplicationDeployment.CurrentDeployment.CurrentVersion; 

But for a no-click application, I'm not sure how to get the clickonce version if I haven't encoded the version number in the assembly.

Is there an automatic way to get the ClickOnce version number for the deployed version without a click?

+50
deployment clickonce
Jul 08 '09 at 13:33
source share
9 answers

No, I do not believe that there is a way. I believe that ClickOnce information comes from a manifest that will only be available when ClickOnce is deployed. I think hardcoded version number is your best option.

+11
Jul 08 '09 at 13:40
source share
  • Add a reference to the System.Deployment assembly in your project.

  • Import namespace into class file:

    VB.NET:

     Imports System.Deployment 

    FROM#:

     using System.Deployment; 
  • Get the version of ClickOnce from the CurrentVersion property.

    You can get the current version from the ApplicationDeployment.CurrentDeployment.CurrentVersion property. This returns a System.Version object.

    Note (from MSDN):

    CurrentVersion will be different from UpdatedVersion if a new update has been installed, but you have not yet called Restart . If the manifest deployment is configured to perform automatic updates, you can compare these two values ​​to determine whether to restart the application.

    NOTE. The static CurrentDeployment property is only effective when the application has been deployed using ClickOnce. Therefore, before accessing this property, you must first check the ApplicationDeployment.IsNetworkDeployed property. It always returns false in the debugging environment.

    VB.NET:

     Dim myVersion as Version If ApplicationDeployment.IsNetworkDeployed Then myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion End If 

    FROM#:

     Version myVersion; if (ApplicationDeployment.IsNetworkDeployed) myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion; 
  • Use the Version object:

    Here you can use the version information on the label, for example, in the "About Me" form:

    VB.NET:

     versionLabel.Text = String.Concat("ClickOnce published Version: v", myVersion) 

    FROM#:

     versionLabel.Text = string.Concat("ClickOnce published Version: v", myVersion); 

    ( Version objects are formatted as a four-part number (major.minor.build.revision).)

+73
May 24 '12 at 9:24
source share

I would just make the build version of the main build the same as the CLickOnce version, every time you release a new version. Then, when it starts as an application without a click, just use Reflection to select the version of the assembly.

+8
Aug 21 '09 at 10:46
source share

Try checking the stream:

 if (ApplicationDeployment.IsNetworkDeployed) { if (ApplicationDeployment.CurrentDeployment.CurrentVersion != ApplicationDeployment.CurrentDeployment.UpdatedVersion) { Application.ExitThread(); Application.Restart(); } } 
+3
Sep 08 '14 at 18:14
source share

Hard code or ... Keep track of the versions (File, Assembly, Deploy) in the database. Make a call to the database with your assembly and get the Deploy version.

This assumes that you are increasing your versions logically, so that each type of version has a relationship. This is a great job for such a minor issue. I would personally go with the decision of Jared; although I hate hard coding.

+2
Jul 08 '09 at 14:16
source share

not that it matters three years later, but in the end I just parsed the manifest file using an xml reader.

+2
Dec 05
source share

To extend RobinDotNet solution:

Protip: you can automatically run a program or script to do this for you from within the .csproj configuration file of MSBuild every time you build. I did this for one web application that I currently support by running the Cygwin bash shell script to do some h4x version control, to calculate the version number from the Git history, and then pre-process the assembled assembly source information file in the assembly output.

A similar thing can be done to analyze the ClickOnce version number from the project file, i.e. Project.PropertyGroup.ApplicationRevision and Project.PropertyGroup.ApplicationVersion (although I don’t know what the version line means, but you can just guess until it breaks and fix it) and insert this version information into the assembly information.

I don’t know when the ClickOnce version is clicked, but probably after the build process, so you may need to tinker with this solution to compile the new number. I assume there is always /*h4x*/ +1 .

I used Cygwin because * nix scripting is much better than Windows, and the interpreted code eliminates the need to create your pre-build before creating it, but you could write the program using whatever technique you wanted (including C # / .NET). The pre-processor command line is inside PreBuildEvent :

 <PropertyGroup> <PreBuildEvent> $(CYGWIN_ROOT)bin\bash.exe --login -c refresh-version </PreBuildEvent> </PropertyGroup> 

Do you think this happens before the build phase, so you can effectively pre-process the source code before compiling it. I did not want to automatically edit the Properties\AssemblyInfo.cs file, so for its safe use I created a Properties\VersionInfo.base.cs file that contained a text template of the class with version information and was marked as BuildAction=None in the project so that it would not be compiled with project:

 using System.Reflection; using EngiCan.Common.Properties; [assembly: AssemblyVersion("0.$REVNUM_DIV(100)$.$REVNUM_MOD(100)$.$DIRTY$")] [assembly: AssemblyRevisionIdentifier("$REVID$")] 

(A very simple and dirty placeholder syntax similar to Windows environment variables with the added extra h4x was used for simplicity / complexity)

AssemblyRevisionIdentifierAttribute was a custom attribute that I created to store Git SHA1, since it is much more meaningful to developers than abcd

My refresh-version program will then copy this file to Properties\VersionInfo.cs , and then replace the version information that it has already calculated / analyzed (I used sed(1) to substitute, which was another advantage of using Cygwin). Properties\VersionInfo.cs been compiled into a program. This file may start empty, and you should ignore it in your version control system, because it automatically changes, and the information for its creation is already stored in another place.

+2
Nov 25 '14 at 20:50
source share

Using the assembly component, you can read a one-time version of the project file and write it automatically to the assembly so that both of them are synchronized.

+1
Dec 10 '09 at 0:57
source share

Do a stream check, paste the protected code ...

+1
Jun 18 '15 at 19:59
source share



All Articles