Azure Web App deploy: Web Deploy cannot modify the file on the destination because it is locked by an external process

24,663

Solution 1

As per a separate thread in the Microsoft Github repo here, there's a hacky workaround where if you add the following key to the Azure Appsettings, it can help resolve the locked file deployment error:

MSDEPLOY_RENAME_LOCKED_FILES = 1

I'm not sure how long this appsetting hack will be supported, but it did help solve the issue for me personally.

enter image description here

Solution 2

I was struggling with the same locking issue.
There are now a new Tasks (in Preview) that you can add for starting and stopping the App Service:

enter image description here

Add a stop task before deployment and a start task after the deployment.

enter image description here

This did the trick for me.

Solution 3

You can restart the Function App to release the lock. After that you should be able to deploy.

enter image description here

Solution 4

I was getting the same error while I was trying to publish my Azure Function App. I followed this Microsoft document and did the following steps.

  1. Right click on your Project and select Edit ....csproj
  2. Add <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline> in PropertyGroup tag

    <PropertyGroup>
      <TargetFramework>netcoreapp2.1</TargetFramework>
      <AzureFunctionsVersion>v2</AzureFunctionsVersion>
      <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
    </PropertyGroup>
    
  3. Save and Rebuild your solution

  4. Now publish again

If that didn't work for you, you can always add MSDEPLOY_RENAME_LOCKED_FILES=1 as Mr. Ben mentioned in his answer, to your Application settings. You can do that from Visual Studio itself.

enter image description here

enter image description here

Hope it helps

Solution 5

You can create two Power Shell scripts:

stopapp.ps1:

param($websiteName)
$website = Get-AzureWebsite -Name $websiteName
Stop-AzureWebsite -Name $websiteName

startapp.ps1:

param($websiteName)
$website = Get-AzureWebsite -Name $websiteName
Start-AzureWebsite -Name $websiteName

And then add an "Azure PowerShell" task before and after "Azure Web App Deployment" task to stop the web app before deploy and start the app after deploy. enter image description here

Share:
24,663
Dave New
Author by

Dave New

Updated on July 09, 2022

Comments

  • Dave New
    Dave New almost 2 years

    I am using the "Azure Web App Deployment" build step in VSTS to publish an ASP.NET Core API to an Azure Web App:

    Azure Web App Deployment

    Occasionally, this step breaks with the following error:

    [error]Microsoft.Web.Deployment.DeploymentDetailedClientServerException: Web Deploy cannot modify the file 'MyProject.Api.exe' 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.

    This GitHub issue raises the same issue, but there is no suggested solution using the Azure Web App Deployment build step.