Private assembly and shared assembly

Source: Internet
Author: User

? Private assemblies:
• By default, C # programs are compiled into private assemblies
• Need to be placed in the same folder as the application
• The name of the Assembly should be unique in the application
? Shared assemblies:
• Can be shared by different applications
• In all applications that use assemblies, the assembly name should be unique
• Placed in the global assembly cache

Global assembly Cache (GAC): A machine-wide code cache that 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.

The GAC is the global Assembly Cache, and his role is to store some common Assembly, such as System.Data, System.Windows.Forms, and so on, that are used by many programs. In this way, many programs can get assembly from the GAC without having to copy all the assembly that are needed to the application's execution directory. For example, if there is no GAC, it is bound to be in the directory of every WinForm program from C:\WINDOWS\Microsoft.NET\Framework\ v1.0.3705 a copy of the System.Windows.Forms.dll below, which is obviously less convenient from the GAC, but also conducive to assembly upgrade and version control.

In addition to the system's default placement in the GAC assembly 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 the GAC.

3) Dynamic loading in the program: System.Reflection.Assembly ass=assembly.load ("Toolbarcomponent, version=1.0.934.20434, culture=neutral , publickeytoken=65f45658c8d4927f ");   MessageBox.Show ("is the assembly loaded from the GAC?" "+ass. GlobalAssemblyCache).

In the above program, Toolbarcomponent is loaded from the GAC instead of from the DLL file in the program's running directory, and the program directory does not need to place the ToolbarComponent.dll program to run properly. In addition, the parameters in Assembly.Load () can be found by "gacutil-l".

In addition, it is mentioned that the assembly in the GAC must be strong-name. The steps to create a strong-name assembly are as follows:

A) Run "sn-k keypair.snk" on the command line to create a key file. The sn.exe here is also a tool that comes with. Net.

b) in vs.net, modify the "AssemblyInfo.cs" file: [Assembly:assemblydelaysign (false)] [Assembly:assemblykeyfile (". \\.. \\keyPair.snk ")] c) Compile the project and you will get a strong-name assembly.

Some of the GAC-related tools are included with the. NET framework, including:

1) Gacutil.exe, a command-line tool for browsing, adding, and deleting assembly in the GAC.

2) Ngen.exe is also a command-line tool for creating native Image in the GAC.

3) Mscorcfg.msc, an MMC terminal, can be graphical to complete the main functions of Gacutil.exe.

From the command line to view the GAC, you can see a lot of internal directory structure, gac_32 mainly store some x86 code cache, gac_64 mainly store some x64 related DLLs.

There are some introductions to the GAC in MSDN, which you can refer to:

1) "Assembly Cache Viewer" (Shfusion.dll)

2) "Global Assembly Cache"

Private assembly and shared 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.