Sunday, May 11, 2008

Microsoft Visual Studio - Web development quickie tip: Quick GAC deployment

I've been across this one so many times before, so I'm adding this entry to remind myself how to automatically deploy compiled libraries to the GAC and recycle the application pool after a successful compilation in Visual Studio 2005/2008:

Add this on the post build events of the Class Library project for quick GAC deployment
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" -i "$(TargetPath)" | C:\Recycle.vbs

Then create a VB Script file using Notepad in location
C:\Recycle.vbs:
strAppPoolName = "DefaultAppPool"
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:{authenticationLevel=pktPrivacy}\\" _
& strComputer & "\root\microsoftiisv2")

Set colItems = objWMIService.ExecQuery _
("Select * From IIsApplicationPool Where Name = " & _
"'W3SVC/AppPools/" &strAppPoolName & "'")

For Each objItem in colItems
objItem.Recycle
Next

Wscript.echo "Recycle Completed"

Change the value of the variable "strAppPoolName" to the name of the application pool that needs recycling.

No comments: