Web deployment task failed – cannot modify the file on the destination because it is locked by an external process

In this azure tutorial, we will discuss how to fix the error, Web deployment task failed – cannot modify the file on the destination because it is locked by an external process. This error I got while trying to Publish the Azure function to Azure using the Visual Studio 2019.

Web deployment task failed – cannot modify the file on the destination because it is locked by an external process

Recently, I got some requirements, Where I had to modify my existing Azure Function using Visual Studio 2019. Where I have added a few lines of code to meet the new requirement. So I modified the Code in my Azure Function Solution and then I tried to Republish the Azure Function from Visual Studio 2019.

When I clicked on the Publish Button I got the below error message

Web deployment task failed – cannot modify the file ‘filename.dll’ on the destination because it is locked by an external process

The complete error message was as below

C:\ProgramFiles\dotnet\sdk\2.1.403\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeploy.target: error : Web deployment task failed. (Web Deploy cannot modify the file ‘MyDemoAzureFunctionApp89.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.

I have tried multiple ways but nothing worked out. Finally I got a solution after struggling a lot.

Web deployment task failed – cannot modify the file on the destination because it is locked by an external process [Solved]

The time, you will try to republish the Azure function, Behind the scene, the existing dlls will get removed and new dlls are being added, there might be some chances that the existing dlls are been used by some process. So they are in the Locked state. This might be the reason we got this error.

Now to fix the issue we need to follow the below steps.

Login to the Azure Portal(https://portal.azure.com/)

Navigate to the Azure Function app that contains your Azure Function that you want to republish

On the Overview Tab of your Azure Function App, Click on the Stop button. It will stop the Azure Function App.

Web deployment task failed - cannot modify the file on the destination because it is locked by an external process

Then, you click on the Yes button for the confirmation

Web deployment task failed cannot modify the file on the destination because it is locked by an external process

Now From the Visual Studio, you try Republishing the Azure Function, It will successfully publish the Azure Function this time.

Now After you Publish the Azure Function, Again navigate to the above Azure Function App Overview tab and click on the Start button to start the Azure Function App service again.

Web deployment task failed cannot modify the file on the destination because it is locked by an external process

It will show you “successfully started the Web App”.

Basically, By stopping and starting the Function App, the Lock is getting released so it is allowing us to publish the Azure Function.

You may also like following the below articles

Wrapping Up

In this article, we discussed How to fix the error, Web deployment task failed – cannot modify the file on the destination because it is locked by an external process. Hope it will help you to fix your issue !!!

Leave a Comment