PowerShell Script for Deploying All Assemblies in a Folder to the GAC

As a SharePoint developer, I find it a lot easier to manually deploy files to the GAC during development instead of allowing Visual Studio to do a complete retract / redeploy.  There are tools out there like CKS Dev that give you the “Copy to GAC” option directly from a project, but I’ve found that option does not always get everything in the GAC that I want.  As such, I’ve started adding a simple post-build command to copy all newly built DLLs into a “Compiled DLLs” folder in the solution root so I have a consolidated set of assemblies to deploy out to the GAC.  Then I run the following PowerShell script that deploys all of the assemblies found in a folder out to the GAC:

$gacUtilLocation = “C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinx64gacutil.exe”;

get-childitem * -include *.dll,*.exe | foreach-object {
    Write-Host “Adding” $asm.FullName
    $asm = [System.Reflection.Assembly]::LoadFile($_)
    $command = “&`”{0}`”/nologo /i `”{1}`”” -f $gacUtilLocation,$_
    invoke-expression $command
}