All Type Coding

Search Here

.Net Assembly

Assembly is a logical unit of code, that contains code which the Common Language Runtime (CLR) executes.Assembly is unit of deployment like EXE or a DLL. An assembly consists of one or more files (dlls, exe’s, html files etc.), and represents a group of resources, type definitions, and implementations of those types. An assembly may also contain references to other assemblies. These
resources, types and references are described in a block of data called a manifest. The manifest is part of the assembly, thus making the assembly self-describing. An assembly is completely self-describing. An assembly contains metadata information, which is used by the CLR for everything from type checking an security to actually invoking the components methods. As all information is in the assembly itself, it is independent of registry. This is the basic advantage as
compared to COM where the version was stored in registry.
 Multiple versions can be deployed side by side in different folders. These different versions can execute at the same time without interfering with each other. Assemblies can be private or shared. For private assembly deployment, the assembly is copied to the same directory as the client program that references it. No registration is needed, and no fancy installation program is required. When the
component is removed, no registry cleanup is needed, and no uninstall program is
required. Just delete it from the hard drive.  In shared assembly deployment, an assembly is installed in the Global Assembly Cache (or GAC). The GAC contains shared assemblies that are globally accessible to all .NET applications on the machine.


Types of Assembly:
There are two types of assembly
1- Private :A private assembly is normally
used by a single application, and is stored in the application's directory, or a sub-directory beneath.
2-and Public assembly.
A shared Assembly is one that can be referenced by more than one application. If multiple applications need to access an Assembly, we should add the Assembly to the Global Assembly Cache (GAC). There is also a third and least known type of an assembly: Satellite Assembly . A Satellite Assembly contains only static objects like images and other non-executable files required by the application.

Difference between NameSpace and Assembly?
A .Net Namespace provides the fundamental unit of logical code grouping while an assembly provides a fundamental unit of physical code grouping.
Namespace can span multiple assembly.

How to Add an assembly to GAC.?
    We can use Gacutil.exe to add strong-named assemblies to the global assembly cache.Type the following at the command prompt.

gacutil -i AssemblyName


AssemblyName name is the name of the assembly to install in the global assembly cache.We can use another option to install assembly in GAC by using Microsoft Windows Installer. This is the recommended and most common way to add assemblies to the global assembly cache.

How to remove an Assembly from GAC ?
At the command prompt type the following to remove the Assembly from GAC.

gacutil /u  AssemblyName (Fully Qualified Name of Assembly)
For Example

gacutil /u "assemblyname,Version=2.0.0.0, Culture=neutral, PublicKeyToken=0213456789ABCDEF"



How to see assembly version in c# .net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ConsoleApplication1
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("The version of the currently executing assembly is: {0}",
                          typeof(Program).Assembly.GetName().Version);
            Console.ReadKey();
        }
    }
}
 

Output:
 


No comments :

Post a Comment