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.
- Administrator rights to the computer on which the shared assembly is being installed
- General familiarity with assemblies in .NET
- General familiarity with the use of tools from the command-line prompt
- Open Visual Studio .NET or Visual Studio 2005.
- Create a new Class Library project named
GAC in Visual Basic .NET or in Visual Basic 2005.
- 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"
- 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.
- 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.
- 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.
- Start Windows Explorer.
- Navigate to C:\WINNT\assembly.
- Find GAC in the list of installed .dll files.
Article ID: 315682 - Last Review: Jul 14, 2008 - Revision: 1