How to clean up wwwroot folder on the target Azure Websites Windows Server before each deployment in VSTS

When using the Azure App Service Deploy task, and you are using the Publish using Web Deploy option, there is an additional option to Remove Additional Files at Destination.

enter image description here

If you check this option, the deployment process will remove any files at the destination where there is no corresponding file in the package that is being deployed.

In other words, it'll remove any left over files from a previous deployment that are no longer required.


For Web Deploy use answer by @Brendan Green.

For Zip Deploy, from Kudu documentation:

When a new build is deployed with zipdeploy, files and directories that were created by the previous deployment but are no longer present in the build will be deleted. Any other files and directories found in the site that aren't being overwritten by the deployment, such as those placed there via FTP or created by your app during runtime, will be preserved.

https://github.com/projectkudu/kudu/wiki/Deploying-from-a-zip-file-or-url

I think it's good enough for most cases.