How to display ClickOnce Version number on Windows Forms

后端 未结 9 716
眼角桃花
眼角桃花 2020-12-23 11:32

I have a windows forms application that is deployed to two different locations.

  • Intranet - ClickOnce
  • Internet - Installed on a citrix farm through Win
相关标签:
9条回答
  • 2020-12-23 11:34

    Using a build component, you could read the click-once version from the project file and write it automatically to the assembly info so both of them are in sync.

    0 讨论(0)
  • 2020-12-23 11:35

    not that it matters three years later, but I ended up just parsing the manifest file with xml reader.

    0 讨论(0)
  • 2020-12-23 11:36

    Do a thread verification, insert harded code...

    0 讨论(0)
  • 2020-12-23 11:39

    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.

    0 讨论(0)
  • 2020-12-23 11:40
    1. Add an assembly reference to System.Deployment to your project.

    2. Import the namespace in your class file:

      VB.NET:

      Imports System.Deployment.Application
      

      C#:

      using System.Deployment.Application;
      
    3. 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 from UpdatedVersion if a new update has been installed but you have not yet called Restart. 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;
      
    4. 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).)

    0 讨论(0)
  • 2020-12-23 11:45

    I would simply make the assembly version of the main assembly the same as the CLickOnce version every time you put out a new version. Then when it runs as a non-clickonce application, just use Reflection to pick up the assembly version.

    0 讨论(0)
提交回复
热议问题