Search This Blog

Tuesday, October 7, 2014

GAC and Sharepoint



When working with SharePoint you will inevitably have to deploy some code to the GAC. Usually it will not be any more then running a PowerShell script like


Install-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010 –GACDeployment


You don’t have to know anything about the GAC when you do this so if that is all you need then this post is not for you.

Say instead you need to install a dll to your GAC for FormsAuthentication. You wrote an awesome membership provider and how do you get it in the GAC





What is the GAC

Just in case you get this as an interview question :)

The GAC (Global Assembly Cache) contains libraries of code that can be accessed by any program on your computer. 

SharePoint uses the GAC  because it is dispersed all over your server, there are aspects of it in your inetpub directory and in the 14/15 (hive) directory and the GAC is a central place for all shared libraries.

Where is the GAC and how to install anything to it.

.NET Less than 4

The GAC for these assemblies is located in “C:/Windows/assembly”. It is possible that you can just drag and drop your assembly into this folder to install it. If this works for you then you are done, if it does not you need to run a gacutil executable. If you have no idea where this executable is then go to the section in this blog about finding the gacutil.

.NET 4.0 and up

For some reason Microsoft decided to move the GAC for these to C:/Windows/Microsoft.NET/assembly. Then there are 3 directories here.  I think by default your assemblies will be installed into GAC_MSIL.
The way to install to this folder is to use the gacutil. If you are using the Windows SDK’s for the gacutil please refer to the following section.

The commands

To Install > gacutil -I “C:\AuthenticationDM.dll”
To Uninstall > gacutil -U “AuthenticationDM.dll”

Finding The gacutil.

  1. Visual Studio - The developer command prompt has the gacutil in it.
  2. Windows SDK’s 7.1 – Download from Microsoft 
    • There are two gacutils here 
      • For .NET 3.0 or less you can use the gacutil found in “C:\Program Files\Microsoft SDKs\Windows\v7.1\bin”
      • For .NET 4.0 or higher you need to use the gacutil found in “C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\NETFX 4.0 Tools” if you use the other one you will get “This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.”  error.

Why I should not use the GAC


No comments:

Post a Comment