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: http://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:
For ARM web app:
Comments (4)

  1. Jason says:

    I’ve been browsing online more than 2 hours today, yet I never found any
    interesting article like yours. It’s pretty worth enough for me.
    In my opinion, if all webmasters and bloggers made good content
    as you did, the internet will be a lot more useful than ever before.

  2. Robert Cotton says:

    Seems like something that should be included in the Deploy Azure RM step provided my Microsoft. I’m excited for all of this new technology, like Azure to become enterprise ready.

  3. Essentially you need to stop – deploy – restart .

    You have many options to do it but to more easy would be:
    1- Extention: Azure App Services – Start and Stop
    you can try the extension “Azure App Services – Start and Stop” https://marketplace.visualstudio.com/items?itemName=rbengtsson.appservices-start-stop

    2- AzureCLI task
    From the build or Deployment windows Add am Azure CLI task (currently in Preview)

    Add one before the Deployment task
    with Inline script:
    azure webapp stop –resource-group NAME_OF_YOUR_RESOURCE_GROUP –name WEBAPP_NAME

    Add another one after the Deployment task
    with Inline script:
    azure webapp start –resource-group NAME_OF_YOUR_RESOURCE_GROUP –name WEBAPP_NAME

    I hope that help.

Skip to main content