Tuesday, June 11, 2013

Add and Remove an Assembly from the GAC using PowerShell

If you need to add or remove an assembly from Global Assembly Cache without installing SDK o VS and you don't want to disable UAC, you can do that using a simple PowerShell script.

Be sure to execute PowerShell in Administrative mode.

To add an Assembly to the GAC

Set-location "c:\temp"
[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:\temp\myassembly.dll")


To remove an Assembly from the GAC

Set-location "c:\temp"
[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:\temp\myassembly.dll")

No comments: