Copying Files out of the Windows GAC

Sometimes you need to get a file out of the GAC on Windows, either to look at in something like .NET Reflector, or maybe to copy a DLL (licensed, of course) to a server when you don’t need (or want) all the other cruft that the installer might drop on the box. I’m not going to judge.

GAC View in Windows Explorer

The GAC can be viewed on a Windows box by heading pointing Explorer to %windir%\assembly, but Explorer abstracts that folder away so that you can only do limited things with items in the GAC. They’ve even gone so far as to make it impossible using any of the GUI filesystem tools in Windows to navigate into the subfolder hierarchy. So, when faced with a GUI that just won’t cooperate, I turn to my trusty friend, the command line.

GAC Directory Structure from Command Prompt

Now, I can see the structure of the files that I’m looking for, and if I look back at the Explorer view, it even provides me clues on where to look. For instance, the fifth column, Processor Architecture, tells me which GAC_ folder I need to look in. For me, I’m almost always interested in GACMSIL. Once in that folder, there is a new folder for each unique entry in the Assembly Name column for the given Architecture, followed by a group of folders following the naming scheme {Version}_{PublicKeyToken} (that’s two underscores between Version and Public Key Token). Inside of this last folder, is my DLL, which I can copy out to another location.

For instance, System.Core, the core DLL for .NET that everyone has anyway, can be found at: %windir%\assembly\GACMSIL\System.Core\\System.Core.dll

GAC Directory Drilldown from Command Prompt

Now that you know how to find the files, it’s trivial to copy them to wherever you need to, for whatever you’re looking to do. Of course, if you use this to break a license or anything else shitty, it’s not my fault.