I'm using poweshell remoting to restart application pool during deployment.
Before delpoyment site is switched to offline mode using app_offline.html.
Also I deploy temporarary web.config to prevent early restarts:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Environment" value="development" />
<add key="Deployment" value="true" />
</appSettings>
<system.web>
<httpRuntime waitChangeNotification="300" maxWaitChangeNotification="300" />
<!-- <customErrors defaultRedirect="app_offline.htm" mode="On"/> -->
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
Then webdeploy installs new version.
The powershell remote commands are executed Stop-WebAppPool -Name $poolName/Start-WebAppPool -Name $poolName.
Then I deploy full web.config and remove app_offline.html.
The problem is that Stop-WebAppPool does not stop pool, it stays forever in Stopping state (according to powershell Get-WebAppPoolState). At the same time I can go to IIS panel and do stop pool manually without any problems. There is single pool, single machine, so everything is correct. Somehow webdeploy and app_offline.html breaks powershell commands, I tested restart script separately it works as expected.
Relevant thread: https://help.octopus.com/t/issues-stopping-app-pools-during-deploy-when-autostart-being-used/20837