locked
Updating Publish Versions in New Releases RRS feed

  • Question

  • Hi,

    I have a VB.NET windows application that is being deployed with ClickOnce.  Each time I republish, the publish version number increments.  I have an About Form that is meant to tell the user which version of the program they are running.  I'm trying to use the FileVersionInfo class to report the version number.  However, I notice that it is returning the Assembly version numbers located in the AssemblyInfo.vb file.  What I'd really like is to either be able to querry the program for the actual publish number, or be able to update the assembly version number to match the publish version (I'm hoping to do this in code rather than by hand each time i publish).  Does anyone know how to do this?

    Thanks,
    Eric
    Tuesday, November 3, 2009 4:18 PM

Answers

  • There's no automatic way to make the assembly version and ClickOnce version match.

    Here's how to get the version number programmatically. Note that you have to be running it as a ClickOnce application to use the ApplicationDeployment namespace, so this checks, and if you are NOT running it as a ClickOnce app, it pulls the assembly information. (For example, if you are running it in Visual Studio).

    We update the assembly versions on all of our projects with each new major version (1.1, 1.2, 1.3, etc), but not the in-between ones. Since only engineering sees the assembly version, we update it so we can tell which version we are working on when we run it from Visual Studio. The customers see the ClickOnce version.

    public string version
    {
      get
      {
        System.Reflection.Assembly _assemblyInfo =
          System.Reflection.Assembly.GetExecutingAssembly();
        string ourVersion = string.Empty;
    
        //if running the deployed application, you can get the version
        //  from the ApplicationDeployment information. If you try
        //  to access this when you are running in Visual Studio, 
        // it will not work.
        if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
        {
          ourVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
        }
        else
        {
          if (_assemblyInfo != null)
          {
            ourVersion = _assemblyInfo.GetName().Version.ToString();
          }
        }
        return ourVersion;
      }
    }
    

    RobinDotNet
    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev
    • Marked as answer by Aland Li Thursday, November 5, 2009 10:01 AM
    Tuesday, November 3, 2009 6:17 PM

All replies

  • There's no automatic way to make the assembly version and ClickOnce version match.

    Here's how to get the version number programmatically. Note that you have to be running it as a ClickOnce application to use the ApplicationDeployment namespace, so this checks, and if you are NOT running it as a ClickOnce app, it pulls the assembly information. (For example, if you are running it in Visual Studio).

    We update the assembly versions on all of our projects with each new major version (1.1, 1.2, 1.3, etc), but not the in-between ones. Since only engineering sees the assembly version, we update it so we can tell which version we are working on when we run it from Visual Studio. The customers see the ClickOnce version.

    public string version
    {
      get
      {
        System.Reflection.Assembly _assemblyInfo =
          System.Reflection.Assembly.GetExecutingAssembly();
        string ourVersion = string.Empty;
    
        //if running the deployed application, you can get the version
        //  from the ApplicationDeployment information. If you try
        //  to access this when you are running in Visual Studio, 
        // it will not work.
        if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
        {
          ourVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
        }
        else
        {
          if (_assemblyInfo != null)
          {
            ourVersion = _assemblyInfo.GetName().Version.ToString();
          }
        }
        return ourVersion;
      }
    }
    

    RobinDotNet
    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev
    • Marked as answer by Aland Li Thursday, November 5, 2009 10:01 AM
    Tuesday, November 3, 2009 6:17 PM
  • Hi Robin, Sorry it took so long for me to try this out. I tried this, but having problems. When I use your lines referring to the System.Deployment.Application.... I run into issues. Namely, visual studio doesn't recognize "Application" as a part of "Deployment". Do I need to somehow turn on the ApplicationDeployment namespace? Thanks, Eric
    Monday, November 9, 2009 7:48 PM
  • Ok I figured it out now.  I needed to do an Imports System.Deployment  in order to make it work.  Now it gives me the publish information.  Perfect!

    Thanks for all the help.
    Monday, November 9, 2009 8:39 PM
  • mmm - and it was oh so simple back in the good old VB6 days.....!!
    With thanks, NECoder
    Thursday, May 26, 2011 5:00 PM