Update a Dll in the GAC From the Command Line

I’ve blogged before on how to Easily add a dll to the GAC, but that involves two instances of Windows Explorer and the mouse.

It would be quicker and easier to use the command line to update a dll in the GAC. You can do this with the Global Assembly Cache Tool gacutil, but this is only present if you have the .net SDK or Windows SDK installed. This is going to be the case with your development machine, but you don’t really want to be installing it on all your test servers.

To get round this I knocked up a quick utility which will remove an existing version of a dll from the GAC and then install the latest version. The code is:

using System;
using System.Globalization;
using System.EnterpriseServices.Internal;

namespace Test
{
public class GacInstall
{
public static void Main(string[] arguments)
{
try
{
string assemblyPath = arguments[0];
Publish publish = new Publish();
publish.GacRemove(assemblyPath);
publish.GacInstall(assemblyPath);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}

You can then use it by passing it the dll you want as a command line parameter e.g.

GacInstall MyUpdatedCode.dll

Assuming that MyUpdatedCode.dll is in the same directory.

Combined with my last tip Recycle An Individual Application Pool From The Command Line you can now write a bat or cmd file to replace the dll in the GAC and recycle the application pool with 2 key presses: The up arrow key and then return.

Richard

I am Managing Director of SalamanderSoft Limited a company devoted to improving IT in education. I am also the project co-ordinator for the open source projects SharePoint Learning Kit and Microsoft Learning Gateway.

Leave a Reply

Your email address will not be published. Required fields are marked *