Monday 5 March 2012

Adding and Removing dll's from the GAC using Powershell

To add a .dll to the GAC

Run the SharePoint PowerShell console as Administrator

type : Set-location <path to dll's here>

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

$publish = New-Object System.EnterpriseServices.Internal.Publish

$publish.GacInstall( <path>\RandomcodemonkeyDLL.dll)


 
To remove a .dll from the GAC

$publish.GacRemove( <path>\RandomcodemonkeyDLL.dll)





A good way of getting the names of you assemblies from  :
 Simplest way to get the strong name of an assembly
http://nileshmandekar.blogspot.co.uk/2012/03/simplest-way-to-get-strong-name-of.html


A very elegant way of getting the dll's in and out via script is like this from Fred :
http://fredericloud.com/2011/01/08/no-gacutil-no-problem/

2 comments:

  1. Subsequently, I would never recommend doing this in an environment you weren't afraid of completely ruining (i.e. this is only okay in a dev. VM, IF you promise to take a snapshot first);

    But if you have programs failing to load because of missing assemblies in the GAC (i.e. Microsoft Preview software, etc.)

    Also, your captcha is awful. I've tried over 10 times now (not counting several I skipped because they were completely unreadable); please use something different. I'll keep trying, and if you ever read this you'll know I made it through, if not, I guess it's moot.

    An addendum such as following run from C:\Program Files & C:\Program Files (x86):

    gci -recu -inc "*.dll" | % { $publish.GacInstall($_.FullName); }


    Also, the link to "getting the names of assemblies" above seems broken. The text is correct (i.e. copy & paste works), but clicking on it navigates to a truncated URL which does not. Please update!

    ReplyDelete
  2. The chaps blog on the broken link seems to have closed but have updated a found a new link which may suit.

    If you point me to the relevant screen shots that are a bit pokey will try update with some text. time is not always me friend but dont mind trying to help solve an issue.

    You are correct about not doing this on prod environments, I would hope that most folk out there would know what not to apply to a prod environment even if you have the access to do it.
    best practice is to always deploy them via solutions.

    ReplyDelete