Monday, December 23, 2013

What is the GAC folder

When developing solutions for SharePoint platform, you will often deploy your solutions to GAC folder and use libraries that are already deployed to GAC, maybe even without knowing it.

What is GAC folder?

Global Assembly Cache (or simply, GAC) is a special folder in Windows designed for storing .NET global DLLs. When you deploy your SharePoint solution, you are actually deploying that DLL to GAC folder.

Location of GAC is C:\Windows\assembly or, in newer versions of .NET Framework (4.0): C:\Windows\Microsoft.NET\assembly

When your try to access those paths, you can see that this isn't the ordinary folder, you can't simply copy/paste files to that folder or delete files from it. Of course, there is a way of opening GAC as ordinary folder, but it is not recommended for you to do it because you can accidentally erase DLL that some other application is using. 

But, if you want to open GAC as "ordinary" folder, do the following steps:
1. Go to Start --> Run
2. Write c:\windows\assembly\gac_msil

And now you can add or delete files form GAC as in any other folder.

Better way of registering/removing solutions to/from GAC, is with use of command prompt, i.e. command line utility gacutil.exe.

If you want to register an assembly in GAC, use command:

gacutil.exe /i <entirePath\assemblyName>
If you want to remove an assembly from GAC, use command:

gacutil.exe /u <assemblyName>

When we are talking about SharePoint Farm solutions, every solution is automatically registered in GAC as soon as you hit "Deploy" in Visual Studio or if you are deploying from command prompt. 

If you want to deploy another library along with your SharePoint solution, the only thing you need is to add that library to the package in your SharePoint solution. 
1. Open the package in Solution Explorer in Visual Studio
2. The package opens in Design view. Click on Advanced tab on the bottom of the package screen.
3. And now, you can add the desired DLL to that package and every time you deploy that SharePoint solution, newly added DLL will also be deployed to GAC.

1 comment: