Fast GAC Deployment and App Pool Recycle for SharePoint Development

Published on
2 mins read
--- views

Fast GAC Deployment for SharePoint Developers

This post will be useful for SharePoint developers. During development, it's common to deploy your .dll to the GAC (Global Assembly Cache) to test or debug new functions or fixes.


Why GAC?

The fastest way is to install your DLL to the GAC and recycle application pools.
While publishing and deploying a full .wsp package is possible, it takes 10x more time.


Two Methods for Fast GAC Deployment

Manual Deploy for Each Project in Solution

Steps:

  1. Build the project.
  2. Set it as the startup project.
  3. Run a custom action for GAC deployment.
  4. Recycle application pools.

I recommend binding these steps to hotkeys for maximum speed.

Configure in Visual Studio:
Go to: Tools → Options → Environment → Keyboard

Visual Studio Keybindings

My mappings (example):

  • Build.BuildSolution: Alt + B
  • Project.SetasStartUpProject: Alt + S
  • Tools.ExternalCommand1: Alt + D (runs gac-deploy.ps1)
  • Tools.ExternalCommand2: Alt + R (runs rec-pools.ps1)
  • Debug.AttachtoProcess: Alt + A

External Commands Configuration:

External Commands

GacDeploy

  • Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Arguments: -file "C:\gac-deploy.ps1" $(TargetPath)
  • Initial Directory: $(ItemDir)
  • Enable: Use Output Window
GAC Deploy Setup

RecPools

  • Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Arguments: -file "C:\rec-pools.ps1"
  • Initial Directory: $(ItemDir)
  • Enable: Use Output Window
Recycle Pools Setup

StrongName (Also Useful)

Get full assembly name via:

  • Command: powershell.exe
  • Arguments:
    -command "[System.Reflection.AssemblyName]::GetAssemblyName(\"$(TargetPath)\").FullName"
    
  1. Automatic Deploy for All Projects via VsCommandBuddy

Steps:

  1. Install the VsCommandBuddy extension
  2. Create .svcb.json config in your solution folder.
  3. Add a deploy command.

Example PowerShell Script

gac-deploy.ps1 (GitHub)

param([String[]]$dllPath)

Import-Module WebAdministration

$gacutil = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe"

foreach($i in $dllPath) {
    Write-Host "[x] Installing $i"
    & $gacutil -i $i
}

& "$PSScriptRoot\Recycle-Pools.ps1"

Recycle-Pools.ps1

Import-Module WebAdministration

$appCmd = "C:\Windows\System32\inetsrv\appcmd.exe"

$appPools = @("SharePoint - 80", "SharePoint - 4448")

foreach ($pool in $appPools) {
    & $appCmd recycle apppool /apppool.name:"$pool"
}

Start-Sleep -Seconds 5

net stop SPTimerV4
net start SPTimerV4

& $appCmd list wp

CommandBuddy Configuration (.svcb.json)

{
  "cmdname": "deploy",
  "title": "deploy",
  "description": "deploy",
  "cwd": "$(SolutionDir)",
  "filename": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
  "arguments": "-command \"C:\\gac-deploy.ps1\" -dllPath  $(SolutionDir)\\Project1\\bin\\$(Configuration)\\Project1.dll,$(SolutionDir)\\Project2\\bin\\$(Configuration)\\Project2.dll,$(SolutionDir)\\Project3\\bin\\$(Configuration)\\Project3.dll",
  "async": false
}
  • $(SolutionDir) – full path to your solution.
  • $(Configuration) – build config (e.g. Debug/Release).

Run it from: Tools → Deploy