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

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


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.


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>