Azure Function: Publish fails with message "Web Deploy cannot modify the file on the Destination because it is locked by an external process."
Asked Answered
B

7

44

I am developing an Azure Functions Project and when I publish first time, OK. Then I publish again, this Error appears:

Web Deploy cannot modify the file 'FunctionApp5.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.

It only Publishes if I enter Azure portal, and Restart this Azure Function App

Azure Portal and Visual Studio 2017

Balduin answered 18/1, 2018 at 20:42 Comment(2)
PS. You get 'Publish failed' for other reasons too - including normal compilation failures. Make sure your app builds fully first before publishing. If the first time you see this it's due to file locking issues that doesn't mean that will always be the reason!Carlotacarlotta
Does this answer your question? Azure Web App deploy: Web Deploy cannot modify the file on the destination because it is locked by an external processChangeup
B
59

Set

MSDEPLOY_RENAME_LOCKED_FILES=1 

in the Azure Function Application Settings usually resolved this

Configure

This can also be done in Visual Studio on the Publish -> Application Settings:

Application Settings

Balduin answered 14/3, 2018 at 14:34 Comment(5)
This should be by default imho and this answer should be marked as the solution.Hamnet
If you are using 'Slot Deployment' you must do this for each slot.Carlotacarlotta
I get this error constantly when I try to deploy Azure Functions. I really hope this is a high priority for Microsoft to fix.Devy
I only get this error when I have the function app open in Azure (i.e. monitoring the function or something). Closing the function app and republishing succeeds.Jeff
The kind of solution that makes my engineers get fired if they try to propose it. Poor Microsoft.Romaineromains
S
4

Following this article, you could also try adding this directive in your Web Deploy pubxml to instruct taking the Function app offline while deploying:

<EnableMsDeployAppOffline>True</EnableMsDeployAppOffline>

Salesmanship answered 9/11, 2018 at 2:25 Comment(0)
K
3

My Azure Function is in V2, and got locked down with FILE_IN_USE.

There is an open issue on this: https://github.com/Azure/azure-functions-host/issues/569

According to Paul Batum's comment from 6 Sep:

"In Functions V2 there is no shadowcopy behavior (because it does not exist in .NET core) and so running into locking issues is more likely. However we have implemented support for the "take app offline" feature that is provided through msdeploy. "

So I checked take app offline and tried, and the file is not locked when I redleploy.

Kauri answered 9/10, 2018 at 12:57 Comment(0)
B
2

Updated Response: Here is some documentation on steps you can take when your files are locked (besides manually restarting your app). https://github.com/projectkudu/kudu/wiki/Dealing-with-locked-files-during-deployment

Belga answered 19/1, 2018 at 21:33 Comment(0)
R
2

As of time of this writing, if you are using Azure DevOps (VSTS) to deploy your application, you can select "Run From Package" in the "Azure App Service Deploy" task/step - this is available in version 4 of the task, under the "Additional Deployment Options" node.

Run From Package

This deployment option eliminates file locking issues as it provides atomicity, in that the application is pointed to the new zip file rather than deploying a bunch of loose files under wwwroot, some of which may be locked.

It provides you with a number of other benefits as documented here.

HTH

Rodriguez answered 10/1, 2020 at 18:2 Comment(0)
A
1

I just had to restart my server, and deploy manually again, and this time the deployment was successful!

Ayer answered 1/8, 2021 at 15:29 Comment(0)
V
0

Go to the Functions tab in Azure and press the Restart button. Then try to publish again in Visual Studio. Sometimes closing the browser and opening it again or a combination of these things are nessesary.

That is all you need to do. enter image description here

Vennieveno answered 14/3, 2018 at 6:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.