Indicate the meaning of GAC

Source: Internet
Author: User

Global Assembly Cache (GAC)
Computer-wide code caching, which stores specially installed assemblies that are shared by many applications on the computer. Applications deployed in the Global Assembly Cache must have a strong name
Yes, all the assemblies in GAC will be stored in the system directory "% winroot %/assembly. One of the advantages of putting it in the system directory is that the system administrator can control assembly access through user permissions.

About GAC itself, the above quoted paragraph is exactly the definition of GAC in msdn. GAC stands for global assembly.
Cache. Its function is to store public assemblies that are used by many programs, such as system. Data and system. Windows. forms.
And so on. In this way, many programs can obtain the Assembly from the GAC without copying all the assembly to the execution directory of the application. For example
If there is no GAC, it is inevitable that the directory of each winform program should be from C:/Windows/microsoft.net/framework
/V1.0.3705 copy a copy of system. Windows. Forms. dll, which is obviously easier to use from the GAC, but also conducive to the Assembly
Upgrade and version control.

In addition to the system default Assembly placed in GAC, such as system. Windows. forms, we can also add our own assembly:
1) create a strong-name Assembly, such as toolbarcomponent. dll.
2) Run gacutil-I toolbarcomponent. dll and add this Assembly to GAC.
3) dynamic loading in the program:
 
System. reflection. Assembly ass = assembly. Load ("toolbarcomponent,
Version = 1.0.934.20434, culture = neutral,
Publickeytoken = 65f45658c8d3167f ");
MessageBox. Show ("is the Assembly loaded from GAC? "+ Ass. globalassemblycache );
 
In the above program, toolbarcomponent is loaded from GAC rather than from the DLL file under the program running directory.
The toolbarcomponent. dll program can also run normally. In addition, parameters in assembly. Load () can be passed through "gacutil
-L.

In addition, the Assembly in GAC must be strong-name. The steps for creating an assembly with strong-name are as follows:
A) Run "Sn-K keypair. SNK" on the command line to create a key file. Sn.exe is also a tool attached to. net.
B) modify the "assemblyinfo. cs" file in vs.net:
[Assembly: assemblydelaysign (false)]
[Assembly: assemblykeyfile (".. // keypair. SNK")]
C) compile the project to get a strong-name assembly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.