You must Sign In to post a response.
  • Category: .NET

    what is assemblyinfo file?

    what is assemblyinfo file in solution explorer? what it's purpose?
  • #258630
    In AssemblyInfo file Informational Attributes contains the information about product Name, description, Trademark, copyright. In general this information's are either hardcode or store in database or flat file. .NET assembly provides to store this information in AssemblyInfo file and after compilation it becomes the part of assembly. So at run time one can read this information.

    Part of Assembly Information

    1 AssemblyTitle : Title name from the assembly.
    2 AssemblyDescription: It provides the detail description from the assembly.
    3 AssemblyCompany: It Provides the company information from the assembly.
    4 AssemblyProduct: It provides the production information from the assembly.
    5 AssemblyCopyright: It Provides the copyright from the assembly.
    6 AssemblyTrademark: It Provides the trademark from the assembly.

    Each of these attributes has a defined class, which is used to read the information from the AssemblyInfo file.

  • #258631
    Follow the Steps below to read the AssemblyInfo File.

    Step 1

    Create VB Windows Application and change the project name to AssemblyInfo.

    Step 2

    Open AssemblyInfo.vb file and edit the file with the changes shown below

    <Assembly: AssemblyTitle("Attribute Information ")>
    <Assembly: AssemblyDescription("Reading the Assembly Attribute Information ")> <Assembly: AssemblyCompany("Company Name")>
    <Assembly: AssemblyProduct(".NET")>
    <Assembly: AssemblyCopyright("Copyright VB.NET All Rights Reserved")>
    <Assembly: AssemblyTrademark("Attribute Information")>

    Step 3

    Create new Class file and rename it to clsAppInfo. Imports system.reflection name space.

    Imports Namespaces
    Imports SR = System.Reflection

    Step 4

    Define one Interface called IAssemblyInfomation with following signature.

    Interface IApplicationSM
    ReadOnly Property Title() As String
    ReadOnly Property Description() As String
    ReadOnly Property Company() As String
    ReadOnly Property Product() As String
    ReadOnly Property Copyright() As String
    ReadOnly Property Trademark() As String
    End Interface

    Step 5

    Create Public class ClsAssInfo and implements the above define interface. Write the implementation of above properties.

    Public Class ClsAssInfo
    Implements IAssInfo
    Dim m_AssInfo As System.Reflection.Assembly
    Sub New()
    m_AssInfo = System.Reflection.Assembly.GetExecutingAssembly
    End Sub
    Public ReadOnly Property Company() As String Implements
    Dim m_Company As SR.AssemblyCompanyAttribute
    m_Company = m_AssInfo.GetCustomAttributes(GetType(SR.AssemblyCompanyAttribute), False)(0)
    Return m_Company.Company.ToString
    End Get
    End Property
    Public ReadOnly Property Copyright() As String Implements
    Dim m_Copyright As SR.AssemblyCopyrightAttribute
    m_Copyright = m_AssInfo.GetCustomAttributes(GetType(SR.AssemblyCopyrightAttribute), False)(0)
    Return m_Copyright.Copyright.ToCharArray
    End Get
    End Property
    Public ReadOnly Property Description() As String Implements
    Dim m_Description As SR.AssemblyDescriptionAttribute
    m_Description = m_AssInfo.GetCustomAttributes(GetType(SR.AssemblyDescriptionAttribute), False)(0)
    Return m_Description.Description.ToString
    End Get
    End Property
    Public ReadOnly Property Product() As String Implements
    Dim m_Product As SR.AssemblyProductAttribute
    m_Product = m_AssInfo.GetCustomAttributes(GetType (SR.AssemblyProductAttribute), False)(0)
    Return m_Product.Product.ToString
    End Get
    End Property
    Public ReadOnly Property Title() As String Implements AssemblyInfo.IAssInfo.Title
    Dim m_Title As SR.AssemblyTitleAttribute
    m_title = m_AssInfo.GetCustomAttributes(GetType(SR.AssemblyTitleAttribute), False)(0)
    Return m_Title.Title.ToString
    End Get
    End Property
    Public ReadOnly Property Trademark() As String Implements
    Dim m_Trademark As SR.AssemblyTrademarkAttribute
    m_Trademark = m_AssInfo.GetCustomAttributes(GetType(SR.AssemblyTrademarkAttribute), False)(0)
    Return m_Trademark.Trademark.ToString
    End Get
    End Property

    Step 6

    Open the Window form and instantiate clsAppInfo class and use clsAppInfo Method to read the Assembly information.

    Description of some function used here


    The System.Reflection namespace provide information about classes and interface that gets loaded dynamically and provides information about data member, function with the ability to dynamically create and invoke types.

    GetExecutingAssembly Function:

    It loads the current assembly that is running form the code. In our case the currently assembly is AssemblyInfo.

  • #258658
    Attributes such as AssemblyTitle or AssemblyCompany were managed from one place and project version was generated with SVN revision based on. AssemblyInfo file wasn't included into the project that's why Solution Explorer didn't even know about its existence. There was no problem with building project and messages about missing AssemblyInfo file despite of absence of this file in SVN repository. Now it is time MSBuild do this same for me :).

    Let's start with example of file compiling which is absent in Solution Explorer. Just add new AssemblyInfo.cs and then make it "Exclude From Project". Now we need to add it dynamicaly to the list of compiled files. Let's modify our actual project file - .csproj, find target named "BeforeBuild" and put there some lines …

    1: <Target Name="BeforeBuild"> 2: <CreateItem Include="AssemblyInfo.cs" Condition="Exists('AssemblyInfo.cs')"> 3: <Output ItemName="Compile" TaskParameter="Include"/> 4: </CreateItem> 5: </Target>
    As you probably noticed AssemblyInfo.cs has been compiled with our project although it is not visible in Solution Explorer.

  • #263470
    Most .Net project deployments are made up of multiple assemblies and it is common to version all assemblies in a given release with the same version numbers. Since changing each AssemblyInfo.cs file can be time consuming and error prone, most projects take one of two approaches to solving the problem:

    1. Generate AssemblyInfo.cs files using an nant build scripts and setting properties.
    2. Use a single AssemblyInfo file and have all projects reference that file.

    Both approaches have pluses and minuses. Generating AssemblyInfo.cs can be hard to setup and get correct but is more flexible. Using a single AssemblyInfo.cs and have each project reference it is easier but all projects will have the same information in the assembly properties.

    A hybrid approach that many developers overlook is splitting AssemblyInfo.cs into an assembly specific version and a product wide version. Each Visual Studio project would contain the standard AssemblyInfo.cs file that is generated by the project templates. The difference would be that product wide attributes are removed. See the sample AssemblyInfo.cs file below for an assembly named ClassLibrary1.dll:

    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;

    // General Information about an assembly is controlled through the following
    // set of attributes. Change these attribute values to modify the information
    // associated with an assembly.
    [assembly: AssemblyTitle("ClassLibrary1")]
    [assembly: AssemblyDescription("Assembly for ClassLibrary1")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCulture("")]

    // Setting ComVisible to false makes the types in this assembly not visible
    // to COM components. If you need to access a type in this assembly from
    // COM, set the ComVisible attribute to true on that type.
    [assembly: ComVisible(false)]

    // The following GUID is for the ID of the typelib if this project is exposed to COM
    [assembly: Guid("e96237d4-2420-4dc7-aed2-43a121bd0221")]

    Notice that several of the standard attributes have been removed. Those attributes are moved to a file in a central directory so that it can be changed once for several projects. The following is the contents of a sample file containing these attributes, named ProductAssemblyInfo.cs:

    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;

    // General Information about an assembly is controlled through the following
    // set of attributes. Change these attribute values to modify the information
    // associated with an assembly.
    [assembly: AssemblyCompany("My Company")]
    [assembly: AssemblyProduct("My Product")]
    [assembly: AssemblyCopyright("Copyright © 2007")]
    [assembly: AssemblyTrademark("")]

    // Version information for an assembly consists of the following four values:
    // Major Version
    // Minor Version
    // Build Number
    // Revision
    // You can specify all the values or you can default the Revision and Build Numbers
    // by using the '*' as shown below:
    [assembly: AssemblyVersion("")]
    [assembly: AssemblyFileVersion("")]

    After creating the product level AssemblyInfo, multiple projects can reference it and pull in those attributes. Below is a snapshot of my Solution Explorer within 2005. Each project has their own AssemblyInfo.cs but each also has a reference to ProductAssemblyInfo.cs. Once the solution is rebuilt, each assembly will have the combination of the attributes in ProductAssemblyInfo.cs and the specific AssemblyInfo.cs.

    Sridhar R
    Nothing is illegal, Until You Get Caught

  • #263789
    The .Net provides few attributes based on the assembly manipulations. Suppose we want to know the current version of the product, then we want to access assembly file and get answer from that file. To achieve the product version attribute in the assembly file, we must use the AssemblyVersionAttribute attribute. And lot's of customization attribute exist in the .Net class library based on the assembly file.

    List of commonly using attributes.

    1. AssemblyTitleAttribute
    2. AssemblyCompanyAttribute
    3. AssemblyVersionAttribute
    4. AssemblyProductAttribute
    5. AssemblyCopyrightAttribute
    6. AssemblyDescriptionAttribute

    Please rate this post, if it is useful for you.

    Thanks & Regards

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.