Categories
VB.net

Get AssemblyInfo

Populating the assembly information of a project compiles this information directly into the class/application/website you’re creating, however it’s also nice to be able to extract this information, for example, to display in an About dialog. Start with:

Imports System.Reflection

Public Shared Function GetAssemblyAttribute(Of T As Attribute)(value As Func(Of T, String)) As String
	Dim myAttribute As T = DirectCast(Attribute.GetCustomAttribute(Reflection.Assembly.GetExecutingAssembly(), GetType(T)), T)
	Return value.Invoke(myAttribute)
End Function

and use this function to extract the attributes you’re looking for.

Public Shared ReadOnly Company As String = GetAssemblyAttribute(Of Reflection.AssemblyCompanyAttribute)(Function(item As Reflection.AssemblyCompanyAttribute) item.Company)
Public Shared ReadOnly Title As String = GetAssemblyAttribute(Of Reflection.AssemblyTitleAttribute)(Function(item As Reflection.AssemblyTitleAttribute) item.Title)

To get the version:

Public Shared ReadOnly Version As Version = Reflection.Assembly.GetExecutingAssembly().GetName().Version

The version can also be used to extract the build date:

Public Shared ReadOnly BuildDate As Date = New DateTime(2000, 1, 1).AddDays(Version.Build).AddSeconds(Version.Revision * 2)

Vars├ągod!

Thanks to:

 

Leave a Reply