Tuesday, March 23, 2010

How to copy from the GAC

If you're not a .NET developer, you probably don't care.  If you are a .NET developer, you've likely had some case where you've got an assembly installed on your development machine, but when you deploy via XCOPY or some other means, the target server doesn't have that DLL and you get an error.  Today I found the trick to copying out of the GAC.

The trick is, you can't use Windows Explorer.  Open an administrative command prompt (Right-click, run as Administrator) and CD to C:\Windows\Assembly.  This directory is not how it appears when viewed from Windows Explorer.  It actually contains a number of directories organized by the type of DLLs it contains.

Most .NET DDLs are MSIL compiled and thus are contained in the GAC_MSIL directory.  The DLLs aren't in there either, instead they're in a sub-sub-directory, the first being the name of the DLL without the ".dll" extension and the second being what looks like a version number/public key token (e.g. Microsoft.SqlServer.SqlClrProvider.dll is contained in C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlClrProvider\10.0.0.0__89845dcd8080cc91).

The easiest way to find your particular DLL is to use the DIR command repeatedly.  You then want to use the COPY or XCOPY commands to copy the DLL somewhere else.

Happy Coding!