To use Visual Studio. NET to create a small class library project, generate a strong name, and install the. dll file of the project in GAC, perform the following steps:
-
- In Visual Studio. NET, create a new Visual C #. Net class library project and name itGacdemo.
-
- Strong names are required. To generate this encryption key pair, use the SN tool. This tool is located in the \ bin subdirectory of the installation. NET Framework Solution Developer kit (SDK. The Sn tool is easy to use. The command line statement is in the following format:
Sn-k "[drive letter]: \ [directory for storing Keys] \ [key name]. SNK"
-
- Create a name in c: \GackeySo that you can easily find the key and access it from the command prompt.
Note:: For most users, the. NET tool is located in c: \ Program Files \ Microsoft. NET \ frameworksdk \ bin. Before you type the following Sn command, you may need to copy a path similar to this path to the. NET bin directory on your computer. EnterCD, Right-click to paste the path, and then press enter to quickly go to the directory where the SN tool is located.
Enter the following content:
Sn-k "C: \ gackey. SNK"
- A key will be generated, but it is associated with the project'sProgramThe set is not associated yet. To establish this association, double-click the assemblyinfo. CS file in Visual Studio. NET Solution Explorer. This file has a list of Assembly properties, which are included by default when you create a project in Visual Studio. NET. InCodeModify the attributes of the assemblykeyfile assembly, as shown below:
[Assembly: assemblykeyfile ("C :\\ gackey \ gackey. SNK ")]
Press Ctrl + Shift + B to compile the project. You can install the. dll file in GAC without additional code.
-
- You can install the. dll file by using the gacutil tool or by dragging the. dll file to an appropriate directory. If you use the gacutil tool, you can use the following command:
Gacutil-I "[drive letter]: \ [path of bin directory in vs project] \ GAC. dll"
To drag a file, use Microsoft Windows Resource Manager. Open two windows Resource Manager instances. In an instance, locate the. dll file output location of the console project. Find c: \ [systemroot] \ assembly in another instance.
Drag your. dll file to the "assembly" folder.
Complete code list (assemblyinfo. CS)
Using system. reflection;
Using system. runtime. compilerservices;
//
// General information about an assembly is controlled through the following
// Set of attributes. Change these attribute values to modify the information
// That is associated with an assembly.
//
[Assembly: assemblytitle ("")]
[Assembly: assemblydescription ("")]
[Assembly: assemblyconfiguration ("")]
[Assembly: assemblycompany ("")]
[Assembly: assemblyproduct ("")]
[Assembly: assemblycopyright ("")]
[Assembly: assemblytrademark ("")]
[Assembly: 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 values, or you can default the revision and build numbers
// By using the '*' as shown below:
[Assembly: assemblyversion ("1. 0. *")]
//
// To sign your Assembly you must specify a key to use. See
// Microsoft. NET Framework documentation for more information about Assembly signing.
//
// Use the following attributes to control that key is used for signing.
//
// Notes:
// (*) If no key is specified, the Assembly is not signed.
// (*) Keyname refers to a key that has been installed in the crypto Service
// Provider (CSP) on your computer. Keyfile refers to a file that contains
// A key.
// (*) If the Keyfile and the keyname values are both specified,
// 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.
// When specifying the Keyfile, the location of the Keyfile must be
// Relative to the project output directory which is
// % Project directory % \ OBJ \
. For example, if your Keyfile is
// Located in the project directory, you wowould specify the assemblykeyfile
// Attribute as [Assembly: assemblykeyfile (".. \ mykey. SNK")]
// (*) Delay signing is an advanced option-see the Microsoft. NET Framework
// Documentation for more information about this.
//
[Assembly: assemblydelaysign (false)]
[Assembly: assemblykeyfile ("C :\\ gackey \ gackey. SNK")]
[Assembly: assemblykeyname ("")]