Microsoft Knowledge Base Email Alertz

KBAlertz.com: (315682) - This article describes how to generate a strong name for an assembly and to install a .dll file in the Global Assembly Cache. The Global Assembly Cache (GAC) enables you to share assemblies across numerous applications. The GAC is automatically...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 315682 - Last Review: May 11, 2007 - Revision: 6.8

How to install an assembly in the Global Assembly Cache in Visual Basic .NET or in Visual Basic 2005

This article was previously published under Q315682

On This Page

SUMMARY

This article describes how to generate a strong name for an assembly and to install a .dll file in the Global Assembly Cache. The Global Assembly Cache (GAC) enables you to share assemblies across numerous applications. The GAC is automatically installed with the .NET runtime. Components are typically stored in C:\WINNT\Assembly.

In order to install an assembly in the GAC, you must give the assembly a strong (that is, globally unique) name. Actually, it is not a name but a cryptographic hash key, or signature. The strong name ensures correct component versioning, which helps to prevent components that have the same name from conflicting with each other or being incorrectly used by a consuming application.

Requirements

The following items describe the recommended hardware, software, network infrastructure, skills and knowledge, and service packs that you need:
  • Administrator rights to the computer on which the shared assembly is being installed
Prior knowledge required:
  • General familiarity with assemblies in .NET
  • General familiarity with the use of tools from the command-line prompt

Global Assembly Cache

To create a small Class Library project by using Visual Studio .NET or Visual Studio 2005, to generate a strong name, and to install the project's .dll file in the Global Assembly Cache, follow these steps:
  1. Open Visual Studio .NET or Visual Studio 2005.
  2. Create a new Class Library project named GAC in Visual Basic .NET or in Visual Basic 2005.
  3. A strong name is needed. To generate this cryptographic key pair, use the SN Tool, which is located in the \bin subdirectory, where the .NET Framework Solution Developer Kit (SDK) is installed. The SN Tool is very easy to use. The command-line statement takes the following form:
    sn -k "C:\[DirectoryToPlaceKey]\[KeyName].snk"
  4. For convenience, create a directory named GACDemo in C:\ so that you can easily locate the key and access the key from the command prompt.

    NOTE: For most users, the .NET tools are located in C:\Program Files\Microsoft.NET\FrameworkSDK\Bin. Before you type the following SN command, you may want to copy this similar path on your computer to the .NET bin directory, type cd from the command prompt, right-click to paste the path, and then press ENTER to quickly change the directory where the SN Tool is located.

    Type the following:
    sn -k "C:\GACDemo\GACkey.snk"
    Note In the .NET Framework 2.0, the .NET tools are located in the C:\Program Files\Microsoft.NET\SDK\v2.0\Bin folder.
  5. A key is generated, but it is not yet associated with the project's assembly. To create this association, double-click the AssemblyInfo.vb file in the Visual Studio .NET or Visual Studio 2005 Solution Explorer. Add the following to the list of assembly attributes that are included in this file by default when a project is created in Visual Studio .NET or in Visual Studio 2005:
    <Assembly: AssemblyKeyFile("C:\GACDemo\GACKey.snk")>
    Compile the project by clicking CTRL+SHIFT+B. No further code is necessary at this point in order to install a .dll file in the GAC.
  6. You can install the .dll file by using the Gacutil Tool or by dragging the .dll file into the appropriate directory. If you use the Gacutil Tool, you can use the following command:
    gacutil -I "C:\[PathToBinDirectoryInVSProject]\gac.dll"
    If you want to drag the file, use Microsoft Windows Explorer. Open two instances of Windows Explorer. In one, navigate to the location of the .dll file output for your console project. In the other, navigate to c:\[SystemRoot]\Assembly.

    Drag your .dll file into the folder.

Complete Code Listing (AssemblyInfo.vb)

Imports System.Reflection
Imports System.Runtime.InteropServices

<Assembly: AssemblyTitle("")> 
<Assembly: AssemblyDescription("")> 
<Assembly: AssemblyCompany("")> 
<Assembly: AssemblyProduct("")> 
<Assembly: AssemblyCopyright("")> 
<Assembly: AssemblyTrademark("")> 
<Assembly: CLSCompliant(True)> 
<Assembly: AssemblyKeyFile("C:\GACDemo\GACKey.snk")> 

<Assembly: Guid("E3492A62-5389-4286-94A3-1331CC29EA6D")> 
<Assembly: AssemblyVersion("1.0.*")> 
				

Verification

  1. Start Windows Explorer.
  2. Navigate to C:\WINNT\assembly.
  3. Find GAC in the list of installed .dll files.

REFERENCES

For more information, visit the following Microsoft Web sites:
Installing an Assembly into the Global Assembly Cache
http://msdn2.microsoft.com/en-us/library/dkkx7f79(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/dkkx7f79(vs.71).aspx)
Global Assembly Cache
http://msdn2.microsoft.com/en-us/library/yf1d93sz(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/yf1d93sz(vs.71).aspx)

Global Assembly Cache Toolhttp://msdn2.microsoft.com/en-us/library/ex0ss12c(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/ex0ss12c(vs.71).aspx)

APPLIES TO
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
Keywords: 
kbvs2005swept kbvs2005applies kbhowtomaster KB315682
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Anonymous User Report As Irrelevant  
Written: 10/4/2008 12:15 AM
I write a code using C#.NET for connecting the ActiveMQ, i referenced a Some .dll files, such as ActiveMQ.dll, NMS.dll, Spring.core.dll etc, while these files have not a strong name, how to add a strong name for those dll files. Please help me if any one know....

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please