Azure api deployment fails with files in use

We’ve been deploying this API application for ages with no troubles. Recently it has begun failing to deploy most of the time with messages like:

Microsoft.Web.Deployment.DeploymentDetailedClientServerException: Web Deploy cannot modify the file 'msvcr120.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. 
September 24th 2019 14:39:39Error
at Microsoft.Web.Deployment.StatusThreadHandler.CheckForException() 
September 24th 2019 14:39:39Error
at Microsoft.Web.Deployment.PackageSerializer.SerializePayload(DeploymentObject obj, Int32 objectId) 
September 24th 2019 14:39:39Error
at Microsoft.Web.Deployment.PackageSerializer.SerializeChildrenDepthFirst(SerializeObjectContext objectContext) 
September 24th 2019 14:39:39Error
at  ....

I have tried using the appoffline setting to ensure that the app is offline when deploying, but it does not seem to have any effect.

How can we fix this?

Edited to add:
I’ve googled this a bit and it has come up in the past with Octopus several time. There never seems to be a satisfactory resolution, or at least not one that details the steps to overcome this issue.
However, something I’ve noticed is that despite loads of requests, and several assurances, the text on the step template still refers incorrectly to an app_offline.html file (instead of app_offline.htm) which makes me wonder whether you just have the wrong filename still:

Hi Dylan,
Thanks for reaching out and providing your insight on this issue.

Unfortunately, you are not alone in your experience, and we’re included in this lucky group. The failure is coming from Webdeploy as it is the one writing the file. Octopus sends the write request to Webdeploy, but that’s where Octopus’s control ends.

You can see how we handle this here https://github.com/OctopusDeploy/Calamari/blob/master/source/Calamari.Azure/Deployment/Conventions/AzureWebAppConvention.cs#L220

I know this may feel like another dead-end, but we do have a backlogged item to move away from WebDeploy. Please don’t hesitate to reach out with further questions or concerns.

So I hear some people use Powershell to stop and start their apps. Any idea how they do it?

Hi Dylan,
Thanks for the followup question.

Absolutely! You can stop and start Azure WebApps by running PowerShell in an Octopus Script step (see below).

You can accomplish this by using the “Run an Azure PowerShell Script” Step Template, along with any of the AzureRMWebApp cmdlet. Here’s a link to the Stop-AzureRMWebApp cmdlet but there is also Start, Restart, Remove, and others listed on the site.

Here’s our documentation on running Azure PowerShell in Octopus that might be helpful.

I hope this helps, but let me know if you have further questions or concerns.

Thank you,

Tina

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.