I am using the "Azure Web App Deployment" build step in VSTS to publish an ASP.NET Core API to an Azure Web App:
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.
There are some dedicated tasks for asp.net core projects because the deployment process is a little bit different.
You can get those from the marketplace for free, check out DNX Tasks vsts marketplace
Hope that helps!!
Eddie's answer was close to what I needed, the only thing that was missing was a way to specify the deployment slot:
stopapp.ps1
startapp.ps1
And then on your Azure PowerShell task Script Arguments could be something like this:
Taking website offline while release should do the trick.
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:
I'm not sure how long this appsetting hack will be supported, but it did help solve the issue for me personally.
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.
Add
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
in PropertyGroup tagSave and Rebuild your solution
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.Hope it helps