If you have ever got involved with putting .NET assemblies into the GAC (Global Assembly Cache), then you will have come across gacutil.exe

There is a problem with gacutil.exe, it isn’t part of the .NET framework and therefore isn’t installed on machines that have had the framework installed on. It is actually part of .NET SDK and you aren’t supposed to distribute it with your own applications.

If like us you don’t realise until late on in your project that gacutil isn’t redistributable then you are faced with a number of options for registering your assemblies with the GAC:

  • use the features in your installer (not an option for us as we were using a very old version of Install Shield)
  • illegally redistribute gacutil
  • write your own code to call the GAC API

I’m ashamed to say that we took option 2 as we were pushed for time and resources. At the time I couldn’t find C# code to call the GAC API and we didn’t have anyone around that could write a C++ version for us.

I have since found this C# code, which is supposed to achieve the task of registering with the GAC:

using System.EnterpriseServices.Internal;

string path = Directory.GetCurrentDirectory() + "\\";
Publish publish = new Publish();
publish.GacInstall(path + "MyAssembly.dll");