.NET 中的 GAC 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1268342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:08:41  来源:igfitidea点击:

What is the GAC in .NET?

.netgac

提问by Nosrama

Just looking for a short overview of GAC for a layman, not a link please.

只是为外行寻找 GAC 的简短概述,而不是链接。

采纳答案by Tom Ritter

Right, so basically it's a way to keep DLLs globally accessible without worrying about conflicts. No more DLL Hell. Each architecture and version gets it's own place to live.

是的,所以基本上它是一种保持 DLL 全局可访问而不必担心冲突的方法。不再有 DLL 地狱。每个架构和版本都有自己的住所。

It also gets it own way to browse it in Explorer, so if you go to

它也有自己的方式在资源管理器中浏览它,所以如果你去

C:\Windows\assembly

C:\Windows\程序集

In windows explorer it lists all the DLLs.

在 Windows 资源管理器中,它列出了所有的 DLL。

But if you fire up cmd, you can see how it's really structured:

但是,如果您启动cmd,您可以看到它的真正结构:

C:\Users\tritter>cd C:\Windows\assembly

C:\Windows\assembly>dir

 Directory of C:\Windows\assembly

07/20/2009  02:18 PM    <DIR>          GAC
06/17/2009  04:22 PM    <DIR>          GAC_32
06/17/2009  04:22 PM    <DIR>          GAC_64
06/17/2009  04:22 PM    <DIR>          GAC_MSIL
 ...snip...
               0 File(s)              0 bytes
               9 Dir(s)  90,538,311,680 bytes free

C:\Windows\assembly>cd GAC_64

C:\Windows\assembly\GAC_64>dir

 Directory of C:\Windows\assembly\GAC_64

06/17/2009  04:22 PM    <DIR>          .
06/17/2009  04:22 PM    <DIR>          ..
01/19/2008  09:54 AM    <DIR>          blbproxy
 ...snip...
01/19/2008  09:54 AM    <DIR>          srmlib
01/19/2008  06:11 AM    <DIR>          System.Data
01/19/2008  06:11 AM    <DIR>          System.Data.OracleClient
 ...snip...
               0 File(s)              0 bytes
              34 Dir(s)  90,538,311,680 bytes free

C:\Windows\assembly\GAC_64>cd System.Data

C:\Windows\assembly\GAC_64\System.Data>dir
 Directory of C:\Windows\assembly\GAC_64\System.Data

01/19/2008  06:11 AM    <DIR>          .
01/19/2008  06:11 AM    <DIR>          ..
04/11/2009  12:20 PM    <DIR>          2.0.0.0__b77a5c561934e089
               0 File(s)              0 bytes
               3 Dir(s)  90,538,311,680 bytes free

C:\Windows\assembly\GAC_64\System.Data>cd 2.0.0.0__b77a5c561934e089

C:\Windows\assembly\GAC_64\System.Data.0.0.0__b77a5c561934e089>dir

 Directory of C:\Windows\assembly\GAC_64\System.Data.0.0.0__b77a5c561934e089

04/11/2009  12:20 PM    <DIR>          .
04/11/2009  12:20 PM    <DIR>          ..
04/11/2009  12:12 PM         3,008,512 System.Data.dll
               1 File(s)      3,008,512 bytes
               2 Dir(s)  90,538,311,680 bytes free

C:\Windows\assembly\GAC_64\System.Data.0.0.0__b77a5c561934e089>

Here you can see version 2.0.0.0__b77a5c561934e089 of System.Data.

在这里您可以看到 System.Data 的 2.0.0.0__b77a5c561934e089 版本。

A DLL is identified by 5 parts:

DLL 由 5 个部分标识:

  1. Name
  2. Version
  3. Architecture
  4. Culture
  5. Public Key
  1. 姓名
  2. 版本
  3. 建筑学
  4. 文化
  5. 公钥

Although the first 3 are generally the big ones.

虽然前3个一般都是大的。

回答by Steven A. Lowe

GAC = Global Assembly Cache

GAC = 全局程序集缓存

Let's break it down:

让我们分解一下:

  • global - applies to the entire machine
  • assembly - what .NET calls its code-libraries (DLLs)
  • cache - a place to store things for faster/common access
  • global - 适用于整个机器
  • 程序集 - .NET 调用其代码库 (DLL) 的内容
  • 缓存 - 一个存储东西的地方,以便更快/公共访问

So the GAC must be a place to store code libraries so they're accessible to all applications running on the machine.

因此,GAC 必须是存储代码库的地方,以便机器上运行的所有应用程序都可以访问它们。

回答by Noldorin

Global Assembly Cache

全局程序集缓存

Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. In addition, it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.

每台安装了公共语言运行时的计算机都有一个机器范围的代码缓存,称为全局程序集缓存。全局程序集缓存存储专门指定由计算机上的多个应用程序共享的程序集。

您应该仅在需要时通过将程序集安装到全局程序集缓存中来共享程序集。作为一般准则,除非明确要求共享程序集,否则请保持程序集依赖项私有,并在应用程序目录中定位程序集。此外,没有必要将程序集安装到全局程序集缓存中以使 COM 互操作或非托管代码可以访问它们。

The things MSDN contains may surprise you... you can usually read it like an article. The straightforward and most important bits at the top, the intricate details deeper down. It certainly explains it better than I could.

MSDN 包含的内容可能会让您感到惊讶……您通常可以像阅读文章一样阅读它。顶部的直接和最重要的部分,更深入的复杂细节。它当然比我能更好地解释它。

Note that Visual Studio displays all the DLLs in the GAC in the .NET tab of the Referenceswindow. (Right-click on a project in Solution Explorer and select Add Reference.) This should give you a more tangeable idea.

请注意,Visual Studio 会在“引用”窗口的 .NET 选项卡中显示 GAC 中的所有 DLL 。(在解决方案资源管理器中右键单击一个项目并选择添加引用。)这应该会给你一个更实际的想法。

回答by Jeff

Centralized DLL library.

集中的 DLL 库。

回答by Kalyan Raj S

The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET assemblies that are specifically designated to be shared by all applications executed on a system. Assemblies can be shared among multiple applications on the machine by registering them in global Assembly cache(GAC). GAC is a machine wide a local cache of assemblies maintained by the .NET Framework.

全局程序集缓存 (GAC) 是 Windows 目录中的一个文件夹,用于存储专门指定由系统上执行的所有应用程序共享的 .NET 程序集。通过在全局程序集缓存 (GAC) 中注册程序集,可以在机器上的多个应用程序之间共享程序集。GAC 是由 .NET Framework 维护的计算机范围内程序集的本地缓存。

回答by INS software

Exe Application, first of all, references from a current directory to a subdirectory. And then, system directory. VS6.0 system directory was ..windows/system32. .NET system directory is like the below GAC path.

exe 应用程序,首先从当前目录到子目录的引用。然后是系统目录。VS6.0 系统目录为 ..windows/system32。.NET 系统目录就像下面的 GAC 路径。

  1. GAC path

    1) C:\Windows\Assembly (for .NET 2.0 ~ 3.5)

    2) C:\Windows\Microsoft.NET\assembly (for .NET 4.0)

  2. How to install an assembly into GAC (as Administrator)

    1) Drag and Drop

    2) Use GacUtil.exe with Visual Studio Command Prompt

     gacutil -i [Path][Assembly Name].dll
    
    • Note: To install an assembly into the GAC, the assembly must be strongly named. Otherwise you get an error like this: Failure adding assembly to the cache: Attempt to install an assembly without a strong name.
  3. How to uninstall an assembly from GAC (as Administrator)

     gacutil -u [Assembly Name], Version=1.0.0.0, PublickeyToken=7896a3567gh
    
    • Note: has no extention, .dll. Version and PublickeyToken can be omitted and be checked in GAC assembly.
  1. GAC路径

    1) C:\Windows\Assembly(适用于 .NET 2.0 ~ 3.5)

    2) C:\Windows\Microsoft.NET\assembly(适用于 .NET 4.0)

  2. 如何将程序集安装到 GAC(以管理员身份)

    1) 拖放

    2) 将 GacUtil.exe 与 Visual Studio 命令提示符一起使用

     gacutil -i [Path][Assembly Name].dll
    
    • 注意:要将程序集安装到 GAC 中,必须对程序集进行强命名。否则,您会收到如下错误:将程序集添加到缓存失败:尝试安装没有强名称的程序集。
  3. 如何从 GAC 卸载程序集(以管理员身份)

     gacutil -u [Assembly Name], Version=1.0.0.0, PublickeyToken=7896a3567gh
    
    • 注意:没有扩展名,.dll。Version 和 PublickeyToken 可以省略并在 GAC 程序集中检查。

回答by ProfK

It's like the COM registry done right, with respect to the physical files as well as their interface and location information. In COM, files were everywhere, with centralised metadata. The GAC centralises the bang shoot.

就物理文件及其接口和位置信息而言,这就像 COM 注册表做得对。在 COM 中,文件无处不在,具有集中的元数据。GAC 集中处理爆炸事件。

回答by fdsf

GAC (Global Assembly Cache) is where all shared .NET assembly reside.

GAC(全局程序集缓存)是所有共享 .NET 程序集所在的位置。