File In Use Error with WebDeploy Publish to Umbraco running on Azure Web App in .NET 6/7
s
Does anyone have a solution to work around the error that occurs when using Visual Studio Publish feature to an Azure Web App. 80-100% of the time the first publish always fails with the following error:
Error: Web deployment task failed. (Web Deploy cannot modify the file '{redacted}.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.)
Our 'solution' currently is to stop the App Service, start it back up, and then Publish while it's loading up. (Note: publishing while it's stopped yeilds another error due to the .scm.azurewebsites.net endpoint not being available). However, I'm hopeful we can get it down to being abl eto just click the Publish button at any time and have a solution in place that handles the take down of the running site, waiting for any running tasks to stop, updating of the files, and restarting the site. Also, about 60% of the time that the first publish fails, we can then re-publish and it will then succeed. I have found a solution called "ShadowCopy" but that appears to be for IIS-hosted sites. It deploys to another folder and then switches when it can (AFAIK). I think something similar could work based on Deployment Slots - which would work manually, but, I'm hoping to find a solution that works the first time we click Publish - without needing to then do additional steps. I'm pretty sure this could be accomplished if we went down the .yaml deployment processes and built out a custom solution that way.. Before we go down that route, I'm hopeful that somebody in the community may have already addressed this and would be willing to either share their solution or perhaps offer insight.
m
we have used the add the
app_offline.htm
via a kudu rest api command call to take the applicaton offline and show a nice maintenance message whilst it's doing it's thing. (and remove it once deploy is done) but that's in a CI/CD githubaction.. The
.scm.azurewebsites.net
should be running in a separate processs by default, there is a configuration setting to override that to be able to access temp folders, are you using that? I think the real recommended approach is to deploy to a deployment slot and then switch?
maybe this? https://stackoverflow.com/a/59163153 for the app_offline.htm approach via vs publish?