Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 846
  • Last Modified:

Application version/build number?

Hi,
How do I programatically  retrieve the version of my application to display in an "About" form, i.e. Major Version, Minor Version, Build Number or Revision? Is this possible? Thanks, Pete.
0
sumo_the_cat
Asked:
sumo_the_cat
  • 4
1 Solution
 
Bob LearnedCommented:
Public Function GetProductVersion(ByVal [assembly] As System.Reflection.Assembly) As String

     Dim attributes() As Object = [assembly].GetCustomAttributes( _
          GetType(System.Reflection.AssemblyInformationalVersionAttribute),False)

     If attributes.Length > 0 Then
          Dim assemblyProductVersion As System.Reflection.AssemblyInformationalVersionAttribute = _
              DirectCast(attributes(0),System.Reflection.AssemblyInformationalVersionAttribute)

         Return assemblyProductVersion.InformationalVersion
     Else
         Return String.Empty
     End If

End Function

Bob
0
 
sumo_the_catAuthor Commented:
Hmm? What do I pass in, bob?
Label1.Text = GetProductVersion(  ?  )
0
 
sumo_the_catAuthor Commented:
... and what goes in place of [assembly] ?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
LacutahCommented:
Here's a simpler way to access it directly from your application:
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.Major
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.Minor
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.Build
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.Revision
0
 
sumo_the_catAuthor Commented:
Sorry bob, just a quicky...! Thanks both, Pete.
0
 
sumo_the_catAuthor Commented:
For future searchers wanting the quick, definitive answer:

System.Reflection.GetExecutingAssembly.GetName.Version.ToString()

gives exactly what I need (e.g., 1.0.1788.33156)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now