Adding Assembly to GAC

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:
[assembly: AssemblyKeyFile("C:\\GACKey\\GACKey.snk")]


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.

Verification
1. Start Windows Explorer.
2. Locate C:\SystemRoot\ assembly.
3. You see GACDemo in the list of installed .dll files.

Comments

Popular posts from this blog

Unable to delete Shared Services Provider in SharePoint (MOSS)

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Cannot add a SimpleContent column to a table containing element columns or nested relations