This post will be useful for SharePoint developers. Due development, it is fairly often need to deploy your dll to gac and test or debug new functions or fixes.
Most fastest way is to install your .dll to GAC and recycle application pools. You can publish and deploy complete .wsp-package also, but it takes much more time. GAC deploy about 10-times faster.
So, in this post will be presented 2 methods for fast gac deploy!
1. Manual deploy for each project in solution
Steps:
- Build project
- Set project as current
- Run custom action for GAC deployment
- Recycle application pools
I recommended to bind command for hotkeys.
Tools -> Options -> Environment -> Keyboard:
My mappings, for example:
- Build.BuildSolution – Alt + B
- Project.SetasStartUpProject – Alt + S
- Tools.ExternalCommand1 – Alt + D (gac-deploy.ps1 script here)
- Tools.ExternalCommand2 – Alt + R (rec-pools.ps1 script here)
- Debug.AttachtoProcess – Alt + A
External commands setup:
GacDeploy:
RecPools:
StrongName (also, rather useful command):
2. Automatic deploy for all projects in solution with VsCommandBuddy
Steps:
- Download and install VsCommandBuddy extension for VisualStudio
- Create .svcb.json file with configs for you solution (solution scope).
- Create new command for deploying
Example:
Deploy script listing allowed here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
param([String[]]$dllPath) Import-Module WebAdministration if([IntPtr]::size -eq 8) { Write-Host 'x64' } else { Write-Host 'x86' } $gacutil = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe" Write-Host "[x] running gacutil" Write-Host "-----------------------------------" foreach($i in $dllPath) { Write-Host "[x] dll path is $i" & $gacutil -i $i Write-Host "-----------------------------------" } & "$PSScriptRoot\Recycle-Pools.ps1" |
As you can see, it runs gacutil.exe for all dllPath-array (passed from parent script from vs). After that, it runs rec-pools script from same folder.
Recycle-Pools listing allowed here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Import-Module WebAdministration if([IntPtr]::size -eq 8) { Write-Host 'x64' } else { Write-Host 'x86' } $appCmd = "C:\Windows\System32\inetsrv\appcmd.exe" Write-Host "App Pool Recycling Started...." & $appCmd recycle apppool /apppool.name:"SharePoint - 80" & $appCmd recycle apppool /apppool.name:"SharePoint - 4448" Write-Host "App Pool Recycling Completed" Write-Host "[x] sleeping for 5 secs" Write-Host "-----------------------------------" sleep(5) Write-Host "[x] restarting sharepoint timer service" Write-Host "-----------------------------------" net stop SPTimerV4 net start SPTimerV4 Write-Host "[x] there are all iis working pools:" Write-Host "-----------------------------------" & $appCmd list wp |
It runs appcmd.exe recycle for all application pools (name filtered). Also, it restarts SharePoint timer service. At the end of execution, it lists all application pools.
Command for CommandBuddy looks so:
1 2 3 4 5 6 7 8 9 |
{ "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 }, |
It calls powershell.exe, pass out script gac-deploy as command with array of all project dll’s. There are some VisualStudio variables used in arguments command, such as:
- $(SolutionDir) – full path to solution directory
- $(Configuration) – Debug/Release/etc.
Run script from Tools -> Deploy: