Using PowerShell to Install a DLL into the GAC

A couple of ways exist to install a DLL into the Global Assembly Cache (GAC). Using gacutil.exe is one, but this comes as part of a Visual Studio installation, and in a server environment, you may not have the luxury of installing Visual Studio, just to get the utility installed.

An alternative, however, is to use PowerShell to install the DLL into the GAC. The following code snippet should take care of your needs.

1#Note that you should be running PowerShell as an Administrator
2[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
3$publish = New-Object System.EnterpriseServices.Internal.Publish            
6#If installing into the GAC on a server hosting web applications in IIS, you need to restart IIS for the applications to pick up the change.
7#Uncomment the next line if necessary...
comments powered by Disqus