How to add assembly to GAC?

Source: Internet
Author: User

First of all, let's talk about GAC. I believe everyone is familiar with it. Its full name is Global Assembly Cache. In my opinion, it is a folder for storing public assemblies. its physical location is % SystemRoot % \ assembly, as long as it is installed. the net framwork folder will exist, in which you can see that the Assembly has vesion, public key, culture and processor architecture information, such:

1.1% SystemRoot % \ assembly

I. What are GAC points?
1. The Assembly above can have the same name. The previous question is to ensure that their versions are different (the third point below explains why the names can be duplicated)
2. The Assembly must be strongly signed (strongrong named)
3. in fact, the % SystemRoot % \ Assembly folder is not what we see. It contains several sub-folders, such as GAC, gac_32, and gac_msil. assembly is placed in these folders, run dir in cmd.

Directory of F: \ windows \ assembly
2010/04/15 13:13 <dir> GAC
2010/03/08 05:23 <dir> gac_32
2010/04/19 :54 <DIR> GAC_MSIL
2010/03/08 12:05 <DIR> NativeImages_v2.0.50727_32
2010/03/08 12:05 <DIR> NativeImages_v4.0.30128_32
2010/03/08 12:05 <DIR> temp
2010/04/19 :54 <DIR> tmp
We can use Tree-f to view the actual storage structure. below is the file storage structure segment under GAC_MSIL.

├ ── Microsoft. datawarehouse. interfaces. resources
│ Examples-9.0.242.0 _ zh-CHS_89845dcd8080cc91 ======> Verison_Culture_PublicKeytoken form subfolders
│ Microsoft. DataWarehouse. Interfaces. resources. dll

Microsoft. ExceptionMessageBox ======> folder named after Assembly
│ ─ ── 10.0.0.0 _ 89845dcd8080cc91 ======> here the middle is _ because this DLL does not have the culture Information
│ Microsoft. ExceptionMessageBox. dll ==> this is the actual DLL

│ ─ ── 9.0.242.0 _ 89845dcd8080cc91 ========> another Version
│ Microsoft. ExceptionMessageBox. dll

As shown above, it is easy to know why GAC can have an Assembly with the same name.

2. How to add your Assembly to GAC
Step 1: Give Assembly a strong name
Method 1:
In the project properties, go to the Signing item, check the Sign the assembly Checkbox, and re-build it.
Method 2:
First, use sn.exe to create an snk file. sn.exe-k c: \ mysn. snk.
In the project properties, go to the Signing item, check the Sign the assembly Checkbox, browse the snk you created above, and build it again.


Method 3:
In the project Assemblyinfo. in the cs file, add [assembly: AssemblyKeyFile (@ "mysn. <G id = "1"> </G>.

If you want to check whether the assembly is strongly named, you can use sn-v [myassembly]. If it is not strongly signed, the information is [myassembly] does not represent a strongly named assembly, if the signature is strong, the information is [myassembly] is valid.
Step 2: add it to GAC
With gacutil.exe-I [myassembly], if you see Assembly successfully added to the cache, congratulations :)

To uninstall a DLL from GAC, you can find the DLL You Want To uninstall under % SystemRoot % \ assembly, right-click it, and choose uninstall

Another method is to use gacutil-U [myassebly] and uninstall it.

PS: sn.exe and gacutil.exe after you install, under % ProgramFiles % \ microsoft sdks \ windows \ v7.0a \ bin, you can find it (the marked area varies depending on the version of your installed vs). You can refer to sn.exeand ganutil.exe, and click sn.exe -? Click it.

Note: My environment is vs2010rc and win7 ultimate.

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.