How to install an assembly to the global assembly cache GAC

For some class library projects or user control projects (generally speaking, one or more dll files are finally compiled and generated by such projects), after the program development is completed, it is sometimes necessary to install and deploy the developed assemblies (dll files) to the GAC (Global Assembly Cache) so that other programs can also call.

Generally speaking, there are several ways to install an assembly (dll) into the GAC:

1. Administrative Tools->Microsoft.NET Framework 2.0 Configuration->Management->My Computer->Assembly Cache->Right click "Add"->Add the assembly to the assembly cache.

2. Manually drag the dll file to be installed and deployed to the assembly folder under the system directory windows (usually C:/windows/assembly). This method is not convenient for installation and deployment.

3. Use the gacutil.exe tool to install: gacutil -i "full path to the dll file to be registered".

     The "gacutil.exe" tool is a built-in tool for .NET (C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin)

  Enter "cmd" in the start operation to enter the command window, and select the directory where the "gacutil.exe" file is located through the CD. For example, enter in the command line: gacutil -i D:/Microsoft.SharePoint.dll


However, beware: you cannot install a weakly named assembly into the GAC . Before proceeding with the above 2-3 methods installation process, we must ensure that this project has a strong name.

Adding a strong name to a project requires three steps:

1. After the project is debugged, use the sn.exe tool to generate a key. sn -k "full path to generated key".
    For example, enter at the command line: sn -k D:/myKey.snk
2. Associate the key with the assembly of the project: Project Properties-->Signing-->Sign the assembly-->Select the strong name key file .
    In addition, there is another method, which is to modify the attribute of "AssemblyKeyFile" in the AssemblyInfo.cs file of the project.
    Such as: [assembly:AssemblyKeyFile("D://myKey.snk")]
3. Regenerate the project set.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325287827&siteId=291194637