Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VS 2017 c# Getting Current Version number

VS 2017 c# Getting Current Version number

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studioannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ormonds
    wrote on last edited by
    #1

    The Properties > Publish page of my App shows a Publish Version of 5.0.0.7. When I use:-

           Assembly assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
    

    it always gives 1.0.0.0. How do I access the version number from the properties page?

    OriginalGriffO 1 Reply Last reply
    0
    • O ormonds

      The Properties > Publish page of my App shows a Publish Version of 5.0.0.7. When I use:-

             Assembly assembly = Assembly.GetExecutingAssembly();
              FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
      

      it always gives 1.0.0.0. How do I access the version number from the properties page?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      These are the methods I use:

          /// /// Gets the assembly Title
          /// 
          public string AssemblyTitle
              {
              get
                  {
                  object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                  if (attributes.Length > 0)
                      {
                      AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes\[0\];
                      if (titleAttribute.Title != "")
                          {
                          return titleAttribute.Title;
                          }
                      }
                  return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
                  }
              }
          /// /// Gets the assembly Version
          /// 
          public string AssemblyVersion
              {
              get
                  {
                  return Assembly.GetExecutingAssembly().GetName().Version.ToString();
                  }
              }
          /// /// Gets the assembly Description
          /// 
          public string AssemblyDescription
              {
              get
                  {
                  object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                  if (attributes.Length == 0)
                      {
                      return "";
                      }
                  return ((AssemblyDescriptionAttribute)attributes\[0\]).Description;
                  }
              }
          /// /// Gets the assembly Product
          /// 
          public string AssemblyProduct
              {
              get
                  {
                  object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                  if (attributes.Length == 0)
                      {
                      return "";
                      }
                  return ((AssemblyProductAttribute)attributes\[0\]).Product;
                  }
              }
          /// /// Gets the assembly copyright notice
          /// 
          public string AssemblyCopyright
              {
              get
                  {
                  object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
      

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      O 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        These are the methods I use:

            /// /// Gets the assembly Title
            /// 
            public string AssemblyTitle
                {
                get
                    {
                    object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                    if (attributes.Length > 0)
                        {
                        AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes\[0\];
                        if (titleAttribute.Title != "")
                            {
                            return titleAttribute.Title;
                            }
                        }
                    return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
                    }
                }
            /// /// Gets the assembly Version
            /// 
            public string AssemblyVersion
                {
                get
                    {
                    return Assembly.GetExecutingAssembly().GetName().Version.ToString();
                    }
                }
            /// /// Gets the assembly Description
            /// 
            public string AssemblyDescription
                {
                get
                    {
                    object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                    if (attributes.Length == 0)
                        {
                        return "";
                        }
                    return ((AssemblyDescriptionAttribute)attributes\[0\]).Description;
                    }
                }
            /// /// Gets the assembly Product
            /// 
            public string AssemblyProduct
                {
                get
                    {
                    object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                    if (attributes.Length == 0)
                        {
                        return "";
                        }
                    return ((AssemblyProductAttribute)attributes\[0\]).Product;
                    }
                }
            /// /// Gets the assembly copyright notice
            /// 
            public string AssemblyCopyright
                {
                get
                    {
                    object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
        
        O Offline
        O Offline
        ormonds
        wrote on last edited by
        #3

        AssemblyVersion still returns 1.0.0.0 despite the Properties > Publish page showing 5.0.0.7. That is with GetExecutingAssembly or with GetEntryAssembly. Am I missing something?

        OriginalGriffO 1 Reply Last reply
        0
        • O ormonds

          AssemblyVersion still returns 1.0.0.0 despite the Properties > Publish page showing 5.0.0.7. That is with GetExecutingAssembly or with GetEntryAssembly. Am I missing something?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Probably, yes. From here though it's difficult to tell what. :laugh: Start by looking in the project Properties folder at the file AssemblyInfo.cs - copy and paste that so we can read it, along with the full path to the file - the version info is normally at the bottom. Then show exactly the code you used, what it displayed, and tell us the location of the file it's in (the full path helps here as well)

          Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          O 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Probably, yes. From here though it's difficult to tell what. :laugh: Start by looking in the project Properties folder at the file AssemblyInfo.cs - copy and paste that so we can read it, along with the full path to the file - the version info is normally at the bottom. Then show exactly the code you used, what it displayed, and tell us the location of the file it's in (the full path helps here as well)

            Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

            O Offline
            O Offline
            ormonds
            wrote on last edited by
            #5

            Thanks, got it. I am getting the correct details from AssemblyInfo.cs. I'll just have to update that and not rely on the automatically incremented Publish Version as on the Properties > Publish page. I'll keep looking for a way to increment the former.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups