.net 如何从 GAC 中提取程序集?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/714907/
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 12:27:42  来源:igfitidea点击:

How to extract an assembly from the GAC?

.netassemblies

提问by AngryHacker

There is a package I have to deal with which installs assemblies straight into the GAC (e.g. somewhere deep in %windows%/assembly).

有一个我必须处理的包将程序集直接安装到 GAC 中(例如在 %windows%/assembly 深处的某个地方)。

How do I exorcise the actual assembly (the DLL) from the GAC into the normal file system?

如何将实际程序集(DLL)从 GAC 驱除到普通文件系统中?

Thanks.

谢谢。

回答by Andrew Hare

I used the advice from this articleto get an assembly from the GAC.

我使用本文中的建议从GAC 获取程序集。

Get DLL Out of The GAC

DLLs once deployed in GAC (normally located at c:\windows\assembly) can't be viewed or used as a normal DLL file. They can't be directly referenced from VS project. Developers usually keep a copy of the original DLL file and refer to it in the project at development (design) time, which uses the assembly from GAC during run-time of the project.

During execution (run-time) if the assembly is found to be signed and deployed in GAC the CLR automatically picks up the assembly from the GAC instead of the DLL referenced during design time in VS. In case the developer has deleted the original DLL or don't have it for some reason, there is a way to get the DLL file from GAC. Follow the following steps to copy DLL from GAC

  1. Run regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll

    • shfusion.dll is an explorer extension DLL that gives a distinct look to the GAC folder. Unregistering this file will remove the assembly cache viewer and the GAC folder will be then visible as any normal folder in explorer.
  2. Open “%windir%\assembly\GAC_MSIL”.

  3. Browse to your DLL folder into the deep to find your DLL.

  4. Copy the DLL somewhere on your hard disk and refer it from there in your project

  5. Run "regsvr32 %windir%\Microsoft.NET\Framework\<.NET version directory> \shfusion.dll" to re-register the shfusion.dll file and regain the original distinct view of the GAC.

从 GAC 中获取 DLL

一旦部署在 GAC(通常位于 c:\windows\assembly)中的 DLL 就不能作为普通的 DLL 文件查看或使用。它们不能直接从 VS 项目中引用。开发人员通常保留一份原始 DLL 文件的副本,并在开发(设计)时在项目中引用它,在项目运行时使用来自 GAC 的程序集。

在执行(运行时)期间,如果发现程序集已在 GAC 中签名和部署,CLR 会自动从 GAC 中获取程序集,而不是在 VS 设计时引用的 DLL。如果开发人员删除了原始 DLL 或由于某种原因没有它,有一种方法可以从 GAC 获取 DLL 文件。按照以下步骤从 GAC 复制 DLL

  1. 运行 regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll

    • shfusion.dll 是一个资源管理器扩展 DLL,它为 GAC 文件夹提供了独特的外观。取消注册此文件将删除程序集缓存查看器,然后 GAC 文件夹将作为资源管理器中的任何普通文件夹可见。
  2. 打开“%windir%\assembly\GAC_MSIL”。

  3. 浏览到您的 DLL 文件夹,深入查找您的 DLL。

  4. 将 DLL 复制到硬盘上的某个位置,然后在项目中从那里引用它

  5. 运行“regsvr32 %windir%\Microsoft.NET\Framework\<.NET版本目录>\shfusion.dll”重新注册shfusion.dll文件,重新获得GAC原有的清晰视图。

回答by Sadjad

The method described here is very easy:

这里描述的方法非常简单:

http://andreasglaser.net/post/2008/08/05/Extract-assembly-from-Global-Assembly-Cache-(GAC)-with-network-drive-mapping.aspx

http://andreasglaser.net/post/2008/08/05/Extract-assembly-from-Global-Assembly-Cache-(GAC)-with-network-drive-mapping.aspx

Summary from Article:

文章摘要:

  • Map a Network Drive (Explorer -> Tools)
    • Map to \servername\folder (\\YourServer\C$\Windows\Assembly)
  • No need for sharing if you are the Administrator
  • Browse to the drive and extract your assembly
  • 映射网络驱动器(资源管理器 -> 工具)
    • 映射到 \servername\folder ( \\YourServer\C$\Windows\Assembly)
  • 如果您是管理员,则无需共享
  • 浏览到驱动器并提取您的程序集

回答by Deepak

Open the Command Prompt and Type :

打开命令提示符并键入:

cd  c:\windows\assembly\GAC_MSIL 

xcopy . C:\GacDump /s /y

This should give the dump of the entire GAC

这应该给出整个 GAC 的转储

Enjoy!

享受!

回答by mccrager

Yes.

是的。

Add DisableCacheViewer Registry Key

添加 DisableCacheViewer 注册表项

Create a new dword key under HKLM\Software\Microsoft\Fusion\ with the name DisableCacheViewer and set it's [DWORD] value to 1.

在 HKLM\Software\Microsoft\Fusion\ 下创建一个名为 DisableCacheViewer 的新 dword 键,并将其 [DWORD] 值设置为 1。

Go back to Windows Explorer to the assembly folder and it will be the normal file system view.

返回到 Windows 资源管理器到程序集文件夹,它将是正常的文件系统视图。

回答by AdamB

I think the easiest way is to do it through the command line like David mentions. The only trick is that the .dll isn't simply located at C:\Windows\Assembly. You have to navigate to C:\Windows\Assembly\GAC\[ASSEMBLY_NAME]\[VERSION_NUMBER]_[PUBLIC KEY]. You can then do a copy using:

我认为最简单的方法是通过 David 提到的命令行来完成。唯一的技巧是 .dll 不仅仅位于 C:\Windows\Assembly。您必须导航到 C:\Windows\Assembly\GAC\[ASSEMBLY_NAME]\[VERSION_NUMBER]_[PUBLIC KEY]。然后,您可以使用以下方法进行复制:

copy [ASSEMBLY_NAME].dll c:\ (or whatever location you want)

复制 [ASSEMBLY_NAME].dll c:\(或您想要的任何位置)

Hope that helps.

希望有帮助。

回答by David M

Easy way I have found is to open the command prompt and browse through the folder you mention until you find the DLL you want - you can then user the copy command to get it out. Windows Explorer has a "helpful" special view of this folder.

我发现的简单方法是打开命令提示符并浏览您提到的文件夹,直到找到所需的 DLL - 然后您可以使用复制命令将其取出。Windows 资源管理器具有此文件夹的“有用”特殊视图。

回答by Hazem Abdel Wahab

Open RUNthen type %windir%\assembly\GAC_MSIL, this will open your dlls in folders' view you can then navigate to your dll named folder and open it, you will find your dll file and copy it easily

打开RUN然后输入%windir%\assembly\GAC_MSIL,这将在文件夹视图中打开你的 dll,然后你可以导航到你的 dll 命名文件夹并打开它,你会找到你的 dll 文件并轻松复制它

回答by Lars Truijens

I am the author of PowerShell GAC. With PowerShell GAC you can extract assemblies from the GAC without depending on GAC internals like changing folder structures.

我是PowerShell GAC的作者。使用 PowerShell GAC,您可以从 GAC 提取程序集,而无需依赖 GAC 内部机制,例如更改文件夹结构。

Get-GacAssembly SomeCompany* | Get-GacAssemblyFile | Copy-Item -Dest C:\Temp\SomeCompany

回答by Bolo

Think I figured out a way to look inside the GAC without modifying the registry or using the command line, powershell, or any other programs:

我想我找到了一种无需修改注册表或使用命令行、powershell 或任何其他程序即可查看 GAC 内部的方法:

Create a new shortcut (to anywhere). Then modify the shortcut to have the target be:

创建一个新的快捷方式(到任何地方)。然后修改快捷方式使目标为:

%windir%\assembly\GAC_MSIL\System

Opening this shortcut takes you to the System folder inside the GAC (which everyone should have) and has the wonderful side effect of letting you switch to a higher directory and then browsing into any other folder you want (and see the dll files, etc)

打开此快捷方式会将您带到 GAC 内的 System 文件夹(每个人都应该拥有),并具有让您切换到更高目录然后浏览到您想要的任何其他文件夹(并查看 dll 文件等)的美妙副作用

I tested this on windows 7 and windows server 2012.

我在 Windows 7 和 Windows Server 2012 上对此进行了测试。

Note: It will not let you use that target when creating the shortcut but it will let you edit it.

注意:它不会让您在创建快捷方式时使用该目标,但可以让您编辑它。

Enjoy!

享受!

回答by MagicAndi

This MSDN blogpost describes three separate ways of extracting a DLL from the GAC. A useful summary of the methods so far given.

这篇MSDN 博客文章描述了从 GAC 中提取 DLL 的三种不同方式。迄今为止给出的方法的有用总结。