Link to home
Start Free TrialLog in
Avatar of TheRookie32
TheRookie32

asked on

How can i get the version number for my DLL?

Is there an assembly i can use to get it?  I built a diagnostic program to get a few pieces of information about the users computer and am converting it into a dll.  The code i used on the form was:

'Application Version Number
                Dim version As String = Forms.Application.ProductVersion.ToString()
                Dim versionparts As String() = Split(version, ".")
                Dim iPos As Long = version.LastIndexOf(".")
                Return version.Substring(0, iPos)

But there isnt any forms in the dll...

Thanks!
Avatar of cookre
cookre
Flag of United States of America image

Use the FileVersionInfo class:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsfileversioninfoclasstopic.asp?frame=true

Note that not all DLLs will have version info.

c# example:
FileVersionInfo fvi=FileVersionInfo.GetVersionInfo(objname);
FoundVer=fvi.FileMajorPart.ToString()+"."
        +fvi.FileMinorPart.ToString()+"."
        +fvi.FileBuildPart.ToString()+"."
        +fvi.FilePrivatePart.ToString();
VB example frpm above link:

Public Sub GetFileVersion()
    ' Get the file version for the notepad.
    Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\Notepad.exe")
   
    ' Print the file name and version number.
    textBox1.Text = "File: " & myFileVersionInfo.FileDescription & ControlChars.Cr & _
        "Version number: " & myFileVersionInfo.FileVersion
End Sub 'GetFileVersion
Avatar of TheRookie32
TheRookie32

ASKER

This wont work within a DLL as its a class and cant have the sub...

This is how i am getting the os version...

Public Shared ReadOnly Property OSVersion()
            Get
                'Display operating system and version
                Return Environment.OSVersion.ToString
            End Get
        End Property

How can i change the code you gave to fit to be a property of a class?
I'm confused now.
Do you want your DLL to determine its own version, or the version of any file specified, or just the OS version?
How are you converting the EXE to a DLL?
Sorry, was in a bit of a rush to get that last post in before i left for the night.  I need it to get the version # of the DLL.  To convert the exe to a dll, i created a new class library and then brought the code over and declared it public, static etc like the example for getting the OS version.  Cheers!
Did i answer your question correctly or do you need more info to solve this one?
If you can't use FileVersionInfo, that pretty much leaves the GetFileVersionInfo() API.  I'll gen up an example later tonight.
You have time to generate an example yet?
Oops - guess who let it slip.  I'll do it this weekend.
ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial