Friday, 5 December 2008

How to get assembly file from GAC?

The .Net application I'm currently working on uses libraries from Global Assembly Cache (GAC). To see the libraries available in GAC just navigate to C:\windows\assembly with regular windows file explorer. The explorer will display the GAC content in a different way than regular files. You'll only see the list of available libraries. You can add assemblies to GAC by drag'n'drop:

Global Assembly CacheHowever, this view will only allow you to see the current GAC content and add/update libraries. This has some limitations e.g.:
  • It won't let you get the actual library file. Sometimes you may need to do that e.g. to backup file from GAC before you replace it.

  • You can't add files of different types e.g. PDB files. This could be useful if you'd like to see the line numbers in stack trace.

  • ...

You can bypass all those limitations by using different tool to access the folder content e.g. console or Total Commander. Note that the libraries placed in GAC are not saved directly in c:\windows\assembly folder. The dll-s you're looking for should be available at following path:
C:\windows\assembly\GAC_MSIL\Namespace.Project\
<assembly_version_number>__<assembly_public_token_key>\Namespace.Project.dll

Example
We're looking for library with name = Kainos.Framework.Web, version = 1.0.0.0 and PublicTokenKey = 1111aaaa1111aaaa. You can find it at:
C:\windows\assembly\GAC_MSIL\Kainos.Framework.Core\
1.0.0.0__1111aaaa1111aaaa\Kainos.Framework.Core.dll
Once you access the folder you can copy the assembly files, add pdb files, etc.

1 comment:

Anonymous said...

You can get the Assembly file by substituting the GAC folder with a virtual drive. Something like
subst g: c:\WINNT\assembly\GAC