Retrieving information from AssemblyInfo.vb

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

What VB run-time methods are available to retrieve
information (such as AssemblyCopyright, AssemblyProduct,
AssemblyVersion, etc.) from the AssemblyInfo.vb file for
the current executable?

Thank you in advance for any help.
 
Hi AAguiar,

Thank you for using Microsoft Newsgroup Service. Based on your description.
You want to get the custom attributes info in the AssemblyInfo.vb file
generated by the VS.NET? If my understanding of your problem is correct,
here is my suggestion:

In dotnet, all such custom attributes are Assembly based. For example, when
you build and run your ASP.NET application, all the atrributes( such as
Copyright,Fileversion) are set as the Assemly Custom Attribute of the whole
Application Assemlbly. You can get such info mation of a dotnet Assembly
via the classes and methods under the "System.Reflection"
namespace.



For example, here is a method to get the currently executing Assembly's
custom attributes: ( you can use it in a ASP.NET application)

Protected Sub GetAssemblyInfo()

Dim curAsm As System.Reflection.Assembly
Dim attrCompany As AssemblyCompanyAttribute
Dim attrConfiguration As AssemblyConfigurationAttribute
Dim attrCopyright As AssemblyCopyrightAttribute
Dim attrCulture As AssemblyCultureAttribute
Dim attrDescription As AssemblyDescriptionAttribute
Dim attrFileVersion As AssemblyFileVersionAttribute


'get the currently executing assembly instance
curAsm = System.Reflection.Assembly.GetExecutingAssembly()

'get the custom attributes in the assembly
Dim attrs() As Object
attrs =
curAsm.GetCustomAttributes(GetType(System.Reflection.AssemblyCompanyAttribut
e), False)
If attrs.Length > 0 Then
attrCompany = attrs(0)
Response.Write("<br>" + attrCompany.Company.ToString())
End If

attrs =
curAsm.GetCustomAttributes(GetType(System.Reflection.AssemblyConfigurationAt
tribute), False)
If attrs.Length > 0 Then
attrConfiguration = attrs(0)
Response.Write("<br>" +
attrConfiguration.Configuration.ToString())
End If

attrs =
curAsm.GetCustomAttributes(GetType(System.Reflection.AssemblyCopyrightAttrib
ute), False)
If attrs.Length > 0 Then
attrCopyright = attrs(0)
Response.Write("<br>" + attrCopyright.Copyright.ToString())
End If

attrs =
curAsm.GetCustomAttributes(GetType(System.Reflection.AssemblyCultureAttribut
e), False)
If attrs.Length > 0 Then
attrCulture = attrs(0)
Response.Write("<br>" + attrCulture.Culture.ToString())
End If

attrs =
curAsm.GetCustomAttributes(GetType(System.Reflection.AssemblyDescriptionAttr
ibute), False)
If attrs.Length > 0 Then
attrDescription = attrs(0)
Response.Write("<br>" + attrDescription.Description.ToString())
End If

attrs =
curAsm.GetCustomAttributes(GetType(System.Reflection.AssemblyFileVersionAttr
ibute), False)
If attrs.Length > 0 Then
attrFileVersion = attrs(0)
Response.Write("<br>" + attrFileVersion.Version.ToString())

End If

'attrFileVersion = (0)



End Sub

For more other infos about using dotnet reflecting to retrieve infomation
in a Assembly file, you can visit the following link on MSDN:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconassemblies.asp?fra
me=true


Please try out the preceding suggestions and let me know whether they help.



Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top