Install a DLL to the GAC on Windows Server 2012 using only PowerShell (without Visual Studio)

Prior to Windows Server 2012 I had been used to install DLL files in the Windows Global Assembly Cache (GAC) by either opening the Windows/Assembly folder and simply dragging and dropping the file, or by using GacUtil.exe

In Windows Server 2012 unfortunately drag and drop feature is gone and with out installing visual studio, you won’t get GacUtil.exe.

Here is the way to register DLL to GAC using PowerShell.

Add a DLL to the GAC
Run the SharePoint PowerShell console as Administrator.
Execute the following command.


Set-location “c:\Dll”
[System.Reflection.Assembly]::Load(“System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”)
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall(“c:\Dll\Sample.dll”)
iisreset

Remove a DLL from GAC
Run the SharePoint PowerShell console as Administrator.
Execute the following command.


Set-location “c:\Dll”
[System.Reflection.Assembly]::Load(“System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”)
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacRemove(“c:\Dll\Sample.dll”)
iisreset

Hope this helps

Happy Coding
Gopinath

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s