Visual Studio Team Services: Azure Web App Deployment failure - ERROR_FILE_IN_USE

As part of a VSTS Release, an Azure Deployment task was failing due to a locked library file preventing the task from modifying the file.  The actual error message is shown below:

##[error]Web Deploy cannot modify the file 'NewRelic.Profiler.dll' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt. Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672\#ERROR\_FILE\_IN\_USE

 The command performed by the task is Publish-AzureWebsiteProject and the command does not support taking the website offline before deployment similar to msbuild publishing.

Stopping the website before the deployment and starting after the deployment does release the lock.

For a classic web app:

    Start-AzureWebsite

    Stop-AzureWebsite

For ARM web app:

    Start-AzureRmWebApp

    Stop-AzureRmWebApp