Results 1 to 8 of 8

Thread: Assembly Version Number

  1. #1

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Assembly Version Number

    In vb6, I could use "App" for displaying the Assembly version number, ie

    VB Code:
    1. Me.Caption = Me.Caption & " [V" & App.Major & "." & App.Minor & "." & App.Revision & "]"

    Is there a similar way of doing it in .Net? I notice there is a system.version class - but have so far only found it used in the system.Environment namespace (and it isn't the assembly version number).

    There best I have found so far is.
    VB Code:
    1. Private Function GetAssemblyVersion() As String
    2.       '* Get the Assembly Version of current object *
    3.       Dim strElements() As String
    4.       Dim strName As String
    5.  
    6.       strName = System.Reflection.GetExecutingAssembly.FullName()
    7.       strElements = strName.Split(CType(",", Char))
    8.  
    9.       Return strElements(1)
    10.   End Function

    But I kind of expected it to be more readably available...

  2. #2
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    In an old Beta 1 book i had, i think they used Application insteal of App, Application.Build or something, i dont have it in front of me to be fully sure tho.
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  3. #3

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    If only it were that simple. There is no Application namespace (as far as I can find anyway).

    Thanks for the reply anyway.

  4. #4
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    When i get home tonight, i will look and see what i am using and let you know, i just dont have it infront of me.
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  5. #5

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    thanks

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    the application object is part of the system.windows.forms namespace
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7
    Lively Member
    Join Date
    Aug 1999
    Location
    Amsterdam
    Posts
    117
    "In vb6, I could use "App" for displaying the Assembly version number"

    Correction, in VB6 you could get the version number of the Component, executable etc. That's very different from an Assembly.

    A process contains AppDomains, and within an AppDomain one or more Assembly get loaded. I wrote a few lines of code to enumerate all the Assemblies within the current AppDomain and get their version numbers:

    Assembly[] myAssemblies = AppDomain.CurrentDomain.GetAssemblies();

    foreach(Assembly myAssembly in myAssemblies)
    {
    Console.WriteLine(myAssembly.GetName().Name);
    Console.WriteLine(myAssembly.GetName().Version);
    Console.WriteLine();
    }
    Console.ReadLine();

    Sorry for the fact that's in C#, personal preference :-)

    (And don't forget to implement the Reflection namespace)

  8. #8

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    Thanks everyone for your help.

    You are correct gijsi, in my first question I guess It would have been more accurate if I had used project instead of assembly.

    There were two reasons I wanted the version number.

    a) to display in the form title bar of the application.

    For this I think I can use either:-
    System.Windows.Forms.Application.ProductVersion
    (thank you Cander and Kleptos for pointing me in the right directiuon for the namespace).

    I could also extract from the executing assembly as follows.

    VB Code:
    1. Dim oASM As System.Reflection.Assembly
    2.       Dim strVersion as String
    3.  
    4.      oASM = System.Reflection.Assembly.GetExecutingAssembly
    5.      strVersion = oASM.GetName().Version()

    Thank you gijsi for helping out with that.

    b) I have an error handler that I use to write to the eventlog, and one of the things I wanted to include was to write the version of the application that bombed. To do this when I pass in the exception I also pass the object that caused the exception (ie, me) and I can then use this objject to extract the name and version.
    For example,

    VB Code:
    1. Public Function ExtractAssemblyVersion(ByVal pvoMe As Object) As Version
    2.       'Extract the Assembly Version of the passed object
    3.       Dim oAssembly As [Assembly]
    4.       Dim oGetAssembly As [Assembly]
    5.       Dim oVersion As System.Version
    6.       oGetAssembly = oAssembly.GetAssembly(pvoMe.GetType)
    7.       oVersion = oGetAssembly.GetName().Version
    8.       Return oVersion
    9.  
    10.    End Function

    Anyway - thanks for the help - it took awhile, but I got there.
    Last edited by Bananafish; Jan 31st, 2002 at 05:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width