Just another tech site

Global Assembly Cache (GAC)


Assembly

In the .NET framework, an assembly is a compiled code library used for deployment, versioning, and security. There are two types: process assemblies (EXE) and library assemblies (DLL). [3]

A Managed module is generally understood to refer to a module that only contains IL code, with no direct machine code.

Assembly in depth

Simple Example

in Visual Studio, let’s create a simple ConsoleApplication

using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Test");
        }
    }
}

in the solution AssemblyInfo.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: AssemblyTitle("ConsoleApplication1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ConsoleApplication1")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[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("482b4e4d-1722-4ad6-a183-ea00a2cc45e0")]

// 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 Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

File Generated

ConsoleApplication1.vshost.exe.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

.NET Reflector

A tool that allow you to explore an assembly.
In our case the same assembly we just build

here is the result

The Portable Executable (PE)

The Portable Executable (PE) format is a file format for executables, object code and DLLs, used in 32-bit and 64-bit versions of Windows operating systems. The term “portable” refers to the format’s versatility in numerous environments of operating system software architecture. [5]

Global Assembly Cache

NOTE:
Assemblies placed in the global assembly cache must have the same assembly name and file name (not including the file name extension). For example, an assembly with the assembly name of myAssembly must have a file name of either myAssembly.exe or myAssembly.dll.

[2]

You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. In addition, it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.

[2]

Advantages of using GAC:
Shared location.
File security.
Side-by-side versioning.
Additional search location.

Add to Global Assembly Cache

You can add a control to the Global Assembly Cache (GAC) by using the Global Assembly Cache tool (Gacutil.exe).
The Global Assembly Cache tool is automatically installed with Visual Studio.

In earlier versions of the .NET Framework, the Shfusion.dll Windows shell extension enabled you to install assemblies by dragging them in Windows Explorer.
Beginning with the .NET Framework version 4, Shfusion.dll is obsolete.

gacutil.exe -i "C:\Program Files (x86)\Telerik\RadControls for ASP.NET AJAX Q2 2010\Bin40\Telerik.Web.UI.dll"

Remove from Global Assembly Cache

please use the following command:

gacutil.exe -u Telerik.Web.UI

Reference

[1] http://www.telerik.com/help/aspnet-ajax/introduction-add-to-global-assembly-cache.html
[2] http://msdn.microsoft.com/en-us/library/6axd4fx6.aspx
[3] http://en.wikipedia.org/wiki/.NET_assembly
[4] http://blog.vuscode.com/malovicn/archive/2007/12/24/net-foundations-net-assembly-structure.aspx
[5] http://en.wikipedia.org/wiki/Portable_Executable

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: