How do I get my .NET Application's Assembly Information?
Similar to Visual Basic 6's App object .NET offers
the Application object which exposes properties
for the CompanyName, ProductVersion and
ProductName values set in the AssemblyInfo.vb
or AssemblyInfo.cs file. For Example:
lblCompany.Text = "Company Name: " & Application.CompanyName.Trim
lblProduct.Text = "Product Name: " & Application.ProductName.Trim
lblVersion.Text = "Version " & Application.ProductVersion.Trim
Other properties such as Assembly Title and
Assembly Description must be retrieved using the System.Reflection
Namespace:
Imports System.Reflection
Dim aAssembly As [Assembly] = _
System.Reflection.Assembly.GetExecutingAssembly
Dim aDescAttr As AssemblyDescriptionAttribute = _
AssemblyDescriptionAttribute.GetCustomAttribute( _
aAssembly, GetType(AssemblyDescriptionAttribute))
Dim aTitleAttr As AssemblyTitleAttribute = _
AssemblyTitleAttribute.GetCustomAttribute( _
aAssembly, GetType(AssemblyTitleAttribute))
Debug.WriteLine(aTitleAttr.Title)
Debug.WriteLine(aDescAttr.Description)
Note: Option Strict must be Off.
using System.Reflection;
lblCompany.Text = "Company Name: " + Application.CompanyName.Trim();
lblProduct.Text = "Product Name: " + Application.ProductName.Trim();
lblVersion.Text = "Version " + Application.ProductVersion.Trim();
AssemblyDescriptionAttribute desc;
AssemblyTitleAttribute title;
Assembly aAssembly = Assembly.GetExecutingAssembly();
desc = (AssemblyDescriptionAttribute)
AssemblyDescriptionAttribute.GetCustomAttribute(
aAssembly, typeof (AssemblyDescriptionAttribute));
title = (AssemblyTitleAttribute)
AssemblyTitleAttribute.GetCustomAttribute(
aAssembly, typeof (AssemblyTitleAttribute));
Console.WriteLine(title.Title);
Consle.WriteLine(desc.Description);
You can also retrieve version, CopyRight, Trademark, Company Name, and other
information from your assembly using the following VB Code:
Imports System.Diagnostics.FileVersionInfo
Imports System.Reflection.Assembly
Dim vi As FileVersionInfo = GetVersionInfo(GetExecutingAssembly.Location)
Console.WriteLine("Major Version: " & vi.ProductMajorPart().ToString())
Console.WriteLine("Minor Version: " & vi.ProductMinorPart().ToString())
Console.WriteLine("Build Number: " & vi.ProductBuildPart ().ToString())
Console.WriteLine("Product Versionr: " & vi.ProductVersion().ToString())
To retrieve the physical folder location of the your DLL or Exe that is
executing, use this VB code:
Dim path as String = _
System.Reflection.Assembly.GetExecutingAssembly.Location
|