SIGN UP MEMBER LOGIN:    
ARTICLE

Installing an Assembly: Part II Using the Global Cache

Posted by Bechir Bejaoui Articles | C# Assemblies January 21, 2008
This article explains installing an Assembly using the Global Cache.
Reader Level:


Introduction

We have seen in a previous article  how one can install a given assembly using the .Net Framework management console the Mscorcfg.msc. Now, we proceed to achieve the same goal but using another tool witch is the Global assembly cache tool cagutil.exe provided by the .Net framework.

To do that, follow those steps:

First of all, let us develop a simple assembly. To do that, follow those steps

  • 1. Create a new class library project and name it myAssembly


@1.gif

Figure 1

  • Add this code to the editor

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

 

namespace myAssembly

{

    public class Class1

    {

        public Class1()

        {

            MessageBox.Show("You are using myAssembly!!!");

        }

    }
}

  • Save the project.

    The GAC accepts only assemblies with strong names ; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.

@2.gif

Figure 2

  • Select the signing tab and then check sign the assembly checkbox

@3.gif

Figure 3

  • Select New in the combo box as shown above. This dialog box appears

@4.gif

Figure 4

  • Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.

    A file looks like this small.gif is added to the application directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe  provided by .NET framework.
  • Build the solution, save the project and close it.
  • Open the console, Start--> Accessories--> Console
  • Browse to your .Net framework directory using the change directory cd command.
  • Tape cagutil -I  myAssembly and the press enter and the windows shell will tell you that the assembly is installed in the assembly cache.

Login to add your contents and source code to this article
share this article :
post comment
 

Thank for the remark

Posted by Bechir Bejaoui Feb 20, 2008

The last lie says " * Tape cagutil -I myAssembly and the press enter and the windows shell will tell you that the assembly is installed in the assembly cache." It is gacutil -I. gacutil is typically found in "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin" if you have installed u r visual studio in C drive. So in cmd go to the specific folder and type gacutil -I"C:\[PathToBinDirectoryInVSProject]\gac.dll"

Posted by Rajesh Thummalapally Feb 04, 2008
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor