For Microsoft Visual Basic .NET versions of this article, see
315682.
This task content
summary
Require global assembly cache full code list (askMBLYINFO.CS) verification reference
SUMMARY This article describes how to generate strong names for the program set, and how to install a DLL file in the Global Jack Cache (GAC). With GAC, you can share the assembly between many applications. The GAC is automatically installed with the .NET runtime. Components are typically stored in C: / WinNT / Assembly.
To install an assembly in the GAC, you must specify a strong name for the assembly. This name is an encrypted hash key or signature. This strong name ensures the correct component version control. This helps prevent components with the same names from conflicting with each other or misuse applications.
Back to top
The following summary lists recommended hardware, software, network structure, and service packs required:
Administrator privileges for the computer where the shared assembly is installed
This article assumes that you are familiar with the following topics:
Generally familiar with the assembly in .NET is generally familiar with the use of tools from the command prompt.
Back to top
Global Program Cache To create a small class library project using Visual Studio .NET, generate a strong name, and install a .dll file in the GAC, please follow these steps:
In Visual Studio .NET, create a new Visual C # .NET class library project and name it Gacdemo. A strong name must be used. To generate this encryption key, use the SN tool. This tool is located in the / bin subdirectory where the .NET Framework Solution Developer Toolkit (SDK) is installed. The SN tool is easy to use. The command line statement uses the following form: Sn -k "[Drive No.]: / [Place the key" / [key name] .snk "creates a directory called gackey in C: /, so you can easily The key is found and the key is accessed from the command prompt. Note: For most users, .NET tools are located in C: / Program Files / Microsoft.Net / FrameworksDK / BIN. Before you type the following SN command, you may need to copy similar paths similar to that path to the .NET bin directory on your computer. Type a CD from the command prompt, right-click to paste the path, then press ENTER to quickly turn to the directory where the SN tool is located. Type the following: Sn -k "c: /gackey/gackey.snk" will generate a key, but it has no association with the program of the project. To establish this association, double-click the assemblyInfo.cs file in the Visual Studio .NET Solution Explorer. This file has a list of assembly properties. By default, these properties will be included when creating a project in Visual Studio .NET. Modify "AssemblyKeyFile" in your code, as shown below: [Assembly: assembly.snk "] By pressing Ctrl Shift B to compile the project. You don't have to have any additional code, you can install the .dll file in the GAC. You can install the .dll file by using the GACUTIL tool or dragging the .dll file to the appropriate directory. If you use the GACUTIL tool, you can use the following command: gacutil -i "[drive letter]: / [vs project in the bin directory path] /gac.dll" If you want to drag file, use Microsoft Windows Explorer . Open two instances of the Windows Explorer. In one example, find the location of the .dll file output of the console project. In another example, find C: / [systemRoot] / askEMBLY. Drag your .dll file to the "Assembly" folder. Back to top
Complete code list (askSEMBLYINFO.CS)
Using system.reflection;
Using system.Runtime.compilerServices;
//
// general information about an assembly is controlled through the folowing
// set of attributes. Change these Attribute Values To Modify The Information
// That is associated with an assembly.
//
[assmbly: assemblytitle ("")]
[assmbly: assemblydescription ("")]
[Assembly: AssemblyConfiguration ("")]
[assmbly: askEMBLYCOMPANY ("")]
[assembly: assemblyproduct ("")] [askMBLY: AssemblyCopyright ("")]]
[assmbly: assemblytrademark ("")]
[assmbly: assemblyculture ("")]
//
// Version Information for an assembly is Made Up of the Following Four Values:
//
// Major Version
// minor version
// build Number
// revision
//
// You can Specify All the value, or you can default the revision and build number
// By Using the '*' As Shown Below:
[assembly: assemblyversion ("1.0. *")]]
//
// TO Sign Your assembly you must specify a key to use. See the
// Microsoft .NET Framework documentation for more information about ask asmbly signing.
//
// Use the follineing attributes to control tria key is buy for signing.
//
// Notes:
// (*) if no key is specified, the assembly is not sign.
// (*) Keyname Refers to a key That Has Been Installed in The Crypto Service
// Provider (CSP) on Your Computer. KeyFile Refers To a file what contains
// a key.
// (*) ife the keyfile and the keyname values area Both Specified, The Key
// Following Processing Occurs:
// (1) if The keyname can be found in the csp, That key is used.
// (2) if the keyname does not exist and the keyfile does exist, the key
// in the keyfile is installed to the csp and used.
// (*) To create a keyfile, you can use the sn.exe (strong name) Utility.
// gen specifying the keyfile, the location of the keyfile must be
// relative to the project Output Directory Which IS
//% project directory% / obj /
// Located in the Project Directory, You Would Specify The assemblyKeyFile
// attribute as [assembly: askEMBLYKEYFILE ("..//// mykey.snk")] // (*) delay signing is an advanced option - See the Microsoft .NET Framework
// Documentation for more information about this.
//
[assmbly: askEDELAYSIGN (FALSE)]
[Assembly: AssemblyKeyFile ("c: //gackey/gackey.snk")]]
[assmbly: assemblykeykeyname ("")]
Back to top
verification
Start the Windows Explorer. Find the C: / [SystemRoot] / assembly. In the list of installed.dll files, you will see Gacdemo.
Back to top
For more information, visit the Microsoft Web site below:
Install the assembly to the global assembly cache http://msdn.microsoft.com/library/en-us/cpguide/html/cpconinstallingassemblyingintoglobalAssemblycache.asp
Global assembly cache http://msdn.microsoft.com/library/en-us/cpguide/html/cpconglobalAssemblycache.asp
Global Program Cache Tool http://msdn.microsoft.com/library/en-us/cptools/html/cpgrfglobalssemblycacheutilityGacutilexe.asp
Back to top
The information in this article applies to:
Microsoft Visual C # .NET (2002) Microsoft Visual C # .NET (2003)
Recent Updated: 2003-9-15 (1.3) Keywords: kbcodesign kbcommandline KBNamespace KbhowTomaster KB815808 KBAUDDEVELOPER