azureazure-devopsazure-pipelines-release-pipelinelocked-files

Azure Devops : How to enable the Rename locked files (RenameFilesFlag) with an "IIS web app deploy" task


I'm having a problem with a locked DLL file while I tried to deploy with a Release Pipeline in Azure Devops.

The screenshot of the error is:

enter image description here

Output as text:

2021-03-31T17:43:18.2626492Z ##[error]Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'Microsoft.Data.SqlClient.SNI.x64.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.
    Error count: 1.

It seems the problem is caused by a wrongly disposed .NET resource. (ex: unmanaged SqlConnection) Anyway, I can't change the source code.

Here is my Release Pipeline.

Azure Devops Release Deploy

Here are my questions:

Q1) I'm trying to use the "-RenameFilesFlag" (MSDEPLOY_RENAME_LOCKED_FILES) as described here:

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops

web.config file locked during Azure App Service Deploy task

How do I have to specify this argument ? Do I have to fill the "Additional arguments" textbox ? I tried different values and I always get an "Unrecognized argument" error.

Q2) If the "-RenameFilesFlag" is not available for this task. Can I use the "Take App Offline" to unlock a file ?

Q3) On another post on StackOverflow, I saw a checkbox option specific to "Rename locked files" Getting ERROR_FILE_IN_USE while using Web Deploy in Azure App Service Task v3

I don`t have this option in my task. Is it possible that I am confusing two type of Deploy tasks ?


Solution

  • MSDEPLOY_RENAME_LOCKED_FILES

    As far as I know, this method only supports Azure Web APP service. This option is used to set the Azure App settings(cloud). It does not apply to IIS deployment(on-prem).

    ##[error]Error Code: ERROR_FILE_IN_USE

    To solve this issue, you could try the following methods:

    1.You could set the Take App Offline option in IIS Web Deploy task.

    enter image description here

    Here is a doc about Taking an Application Offline before Publishing

    2.You could Stop your website before deploying the app and restart it after deployment.

    You could add IIS web app manage task to stop and start the IIS Website.

    For example:

    enter image description here

    Update1:

    As ssinfod's comment: stop the application pool could solve this issue.

    We can also achieve this in IIS web app manage task

    enter image description here