Web deployment task failed - cannot modify the file 'xxx.dll' on the destination because it is locked by an external process.

{tocify} $title={Table of Contents}


Problem 



When you create function using portal, the moment you save it - it is deployed. 

Whereas when you develop using visual studio, one extra step gets added i.e. publishing it to Azure.

When you publish,the .dll file gets uploaded and thus code is not visible in portal.
So if any changes have to be done, you revisit VS, do the change and publish.

And while doing the same, below error was encountered.



Error


C:\ProgramFiles\dotnet\sdk\2.1.403\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeploy.targets(139,5): error : Web deployment task failed. (Web Deploy cannot modify the file 'DevT.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.) [E:\xxx\xxx\DemoProjects\DevT\DevT\DevT.csproj] Publish failed to deploy.




Why it happened


Whenever you deploy, in background the existing dll gets removed and new dll is added.

And sometimes it happens that the existing dll is been used by some process, also sometimes it is not used but the lock is not removed or remains due to some reasons .

So when you try to remove dll having lock over it, you are not allowed and thus the error.




What to do



There are two solutions mentioned in the error message  to resolve this issue

i. restart your application to release the lock
ii.use the AppOffline rule handler for .Net applications on your next publish attempt

Both the option are going to do same thing i.e. stopping the App(thus releasing locks) and starting it once deployment/publishing is completed, difference is that first approach is manual.

I went ahead with first option, stopped the Function App in which function was to be deployed, published the code from my local machine and started the Function App. 

Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post