I have Windows Server 2003 (IIS 6.0) and Windows Server 2008 (IIS 7.0) servers, and I use MSBuild for deploying web applications.
I need to do a safe deploy, and do
Write a script, e.g. PowerShell, which will stop/start IIS web site programmatically relying on command-line argument, e.g. start-stop.ps1 /stop 1
start-stop.ps1 /stop 1
Put it into MsBuild script as a custom step
Check this to find out how to restart IIS AppPool
IIS WMI objects reference