To create a small Class Library project by using Visual Studio .NET, to generate a strong name, and to install the .dll file of the project in the GAC, follow these steps:
1. In Visual Studio .NET, create a new Visual C# .NET Class Library project, and name the project GACDemo.
2. You must use a strong name. To generate this cryptographic key-pair, use the SN Tool. This tool is located in the \bin subdirectory where the .NET Framework Solution Developer Kit (SDK) is installed. The SN Tool is easy to use. The command-line statement takes the following
form:sn -k "[DriveLetter]:\[DirectoryToPlaceKey]\[KeyName].snk"
3. Create a directory named GACKey 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 to the directory where the SN Tool is located.Type the following:
sn -k "C:\GACKey\GACkey.snk"
4. A key is generated, but it is not yet associated with the assembly of the project. To create this association, double-click the AssemblyInfo.cs file in Visual Studio .NET Solution Explorer. This file has the list of assembly attributes that are included by default when a project is created in Visual Studio .NET. Modify the AssemblyKeyFile assembly attribute in the code as follows:
Compile the project by clicking CTRL+SHIFT+B. You do not have to have any additional code to install a .dll file in the GAC.
5. You can install the .dll file by using the Gacutil Tool, or by dragging the .dll file to the appropriate directory. If you use the Gacutil Tool, you can use the following command:
gacutil -I "[DriveLetter]:\[PathToBinDirectoryInVSProject]\gac.dll"
If you want to drag the file, use Microsoft Windows Explorer. Open two instances of Windows Explorer. In one instance, find the location of the .dll file output for your console project. In the other instance, find c:\[SystemRoot]\Assembly.Drag your .dll file to the Assembly folder.
1. Start Windows Explorer.
2. Locate C:\SystemRoot\ assembly.
3. You see GACDemo in the list of installed .dll files.