'Microsoft.CodeAnalysis.CSharp.dll' Locked Problem Fix

If you deploy to Azure App Service Web Apps often enough, eventually you will run into the dreaded error below:

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

The only solution is to restart the Web App and attempt your deployment again. When you are implementing DevOps, you cannot have an inconsistent pipeline.  We need a solution that will guarantee a consistent deployment.  I am sure many of you are thinking, “We use Deployment Slots so we are safe.” Well, not completely.  If you run smoke tests on your staging slot before swapping into production, future deployments to your staging slot could result in the same error. The only way that I have achieved 100% reliability is to stop the slot you plan to deploy to then deploy into the stopped slot.  After you safely deploy your changes, you restart the slot and finally swap it into production.

Now to implement this in a DevOps pipeline you need a way to automate the stopping, starting, and swapping of my slots.  Visual Studio Teams Services recently added a Start/Stop Task. This task allows you to stop a single slot of a Web App while leaving the other slots running. Now you can safely stop the slot you want to deploy to, use the Azure Web App Deployment Task, restart the slot, and finally swap the slots. 


Comments (5) -

  • Erik Taylor

    8/17/2016 8:13:41 PM | Reply

    The thing about Trackyon that made this less than optimal is that it requires an Azure Classic subscription connection.  There are other extensions which allow you to use Azure RM, which I prefer.

    • Donovan

      8/28/2016 8:33:09 PM | Reply

      That is good feedback. I will see about updating them to support them both.

  • Erdem sahin

    10/30/2017 9:51:54 AM | Reply

    should we stop the service or restart it?

    what is the difference

    • Donovan

      12/3/2017 2:07:26 PM | Reply

      Both should work. I think when I wrote this restart was not supported.

Add comment