Search Amazon:

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.

C# code:

    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

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms