141

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

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

Thanks.

starblue
  • 55,348
  • 14
  • 97
  • 151
AngryHacker
  • 59,598
  • 102
  • 325
  • 594

15 Answers15

151

I used the advice from this article to get an assembly from the 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.

cjones26
  • 3,459
  • 1
  • 34
  • 51
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • 82
    This works but is a little complicated. If you are not afraid of the command prompt, you can just cd into the necessary directory and copy the DLL that way. – Cheeso May 27 '09 at 18:56
  • 3
    Just install TotalCommander, enable the option to see all hidden files and you can grab every assembly you want – Patrick Peters Feb 23 '12 at 15:57
  • 4
    @Andrew, it looks like `shfusion.dll` does not support the `DllInstall()` entry point invoked by `regsvr32` when passed the `/i` option. Omitting that option allows to re-register the component successfully. – Frédéric Hamidi Jul 31 '13 at 15:35
  • 9
    You can skip step 1 and 2, and go directly to %windir%\assembly\GAC_MSIL and browse from there. – Christian Fredh Aug 21 '13 at 10:04
  • 5
    @ChristianFredh Just a note: for me, this can only be done directly from the Run dialog. – xr280xr Nov 20 '13 at 00:50
  • I'm curious how accessing the folder via the Run dialog is able to bypass the viewer presumably without unregistering the dll or modifying the registry. – xr280xr Nov 20 '13 at 00:57
  • @xr280xr That is true for me as well. At least currently on my Windows 7 machine. – Christian Fredh Nov 20 '13 at 08:20
  • For those of you trying to copy from the comment prompt, for some reason trying to copy the version of the DLL with a working path of GAC_MSIL directory generated a small junk file for me, but when I changed my working directory to that of the assembly and then copied the appropriate version without specifying a destination file name it worked and even created the proper file name automatically. – Kaganar Jul 25 '14 at 13:56
  • 1
    For it to work for me I had to: 1) Run the command prompt as *administrator*, as although the regsvr command appeared to work OK it didn't. 2) Run the Windows explorer as *administrator* to be able to view "..\GAC_MSIL" folder. I also had to go through the whole process again this morning. For some reason the shfusion.dll registration was gone again today. It may be a group policy wiped it out on restart though – Dib Oct 28 '16 at 07:40
  • 1
    Also note that GAC assemblies might be in `%windir%\Microsoft.NET\assembly\...` instead of `%windir%\assembly\...` – Jez Nov 28 '16 at 16:49
  • @xr280xr It does open Windows Explorer with the targeted folder. But FWIW I personally used the command prompt as administrator method. – Teorist May 31 '18 at 15:01
109

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

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
theChrisKent
  • 15,029
  • 3
  • 61
  • 62
Sadjad
  • 1,661
  • 2
  • 13
  • 20
99

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

Enjoy!

mornaner
  • 2,424
  • 2
  • 27
  • 39
Deepak
  • 991
  • 6
  • 2
27

Yes.

Add DisableCacheViewer Registry Key

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

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

mccrager
  • 1,038
  • 6
  • 13
16

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:

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

Hope that helps.

AdamB
  • 8,850
  • 5
  • 22
  • 14
14

Open RUN then 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

13

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.

David M
  • 71,481
  • 13
  • 158
  • 186
  • I found an interesting issue this morning. I was updating a DLL in the GAC, and used the cmd line method to take a backup. When I tried to upload the new DLL (same version number), I received an error which only went away when I shut down the cmd window. Took me a few minutes of cursing to find out what was going wrong! – NeilD Dec 08 '10 at 09:00
5

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.

Get-GacAssembly SomeCompany* | Get-GacAssemblyFile | Copy-Item -Dest C:\Temp\SomeCompany
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
3

Use the file browser "Total Commander" instead.

  1. Enable the "show hidden/system files" setting in Total Commander
  2. Browse to "c:\windows\assembly"
  3. copy
Max
  • 3,280
  • 2
  • 26
  • 30
3

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

Tangiest
  • 43,737
  • 24
  • 82
  • 113
3

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:

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)

I tested this on windows 7 and windows server 2012.

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

Enjoy!

Bolo
  • 1,494
  • 1
  • 19
  • 19
2

From a Powershell script, you can try this. I only had a single version of the assembly in the GAC so this worked just fine.

cd "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\"
Get-ChildItem assemblypath -Recurse -Include *.dll |  Copy-Item -Destination "c:\folder to copy to"

where the assembly path can use wildcards.

Phil Kermeen
  • 139
  • 1
  • 4
2

just navigate to C:\Windows find the [assembly] folder right click and select add to archive

wait a little

vola you have an archive file containing all the assemblies in your GAC

tsadigov
  • 21
  • 1
0

One other direction--just unpack the MSI file and get the goodies that way. Saves you from the eventual uninstall . . .

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53
0

Copying from a command line is unnecessary. I typed in the name of the DLL from the Start Window search. I chose See More Results. The one in the GAC was returned in the search window. I right clicked on it and said open file location. It opened in normal Windows Explorer. I copied the file. I closed the window. Done.