|
-
Jan 30th, 2002, 11:45 AM
#1
Thread Starter
Hyperactive Member
Assembly Version Number
In vb6, I could use "App" for displaying the Assembly version number, ie
VB Code:
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:
Private Function GetAssemblyVersion() As String
'* Get the Assembly Version of current object *
Dim strElements() As String
Dim strName As String
strName = System.Reflection.GetExecutingAssembly.FullName()
strElements = strName.Split(CType(",", Char))
Return strElements(1)
End Function
But I kind of expected it to be more readably available...
-
Jan 30th, 2002, 12:13 PM
#2
Hyperactive Member
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)

-
Jan 30th, 2002, 12:22 PM
#3
Thread Starter
Hyperactive Member
If only it were that simple. There is no Application namespace (as far as I can find anyway).
Thanks for the reply anyway.
-
Jan 30th, 2002, 12:26 PM
#4
Hyperactive Member
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)

-
Jan 30th, 2002, 12:28 PM
#5
Thread Starter
Hyperactive Member
-
Jan 30th, 2002, 01:50 PM
#6
the application object is part of the system.windows.forms namespace
-
Jan 30th, 2002, 05:26 PM
#7
Lively Member
"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)
-
Jan 31st, 2002, 05:35 AM
#8
Thread Starter
Hyperactive Member
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:
Dim oASM As System.Reflection.Assembly
Dim strVersion as String
oASM = System.Reflection.Assembly.GetExecutingAssembly
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:
Public Function ExtractAssemblyVersion(ByVal pvoMe As Object) As Version
'Extract the Assembly Version of the passed object
Dim oAssembly As [Assembly]
Dim oGetAssembly As [Assembly]
Dim oVersion As System.Version
oGetAssembly = oAssembly.GetAssembly(pvoMe.GetType)
oVersion = oGetAssembly.GetName().Version
Return oVersion
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|