Search code examples
azure-devopsyamlcontinuous-deploymentazure-pipelines-release-pipelinemicrosoft-data-sqlclient

Azure release pipeline (YAML) IIS web deploy fails on locked files generating ERROR_FILE_IN_USE


Actual

Release pipeline fails when deploying

Expected

Deploy does not fail

Root cause

File 'Microsoft.Data.SqlClient.SNI.x86.dll' is locked locked by an external process, even when 'Take App Offline Flag' setting is on

Workaround

Recycle application pool manually and rerun failed deploy.

Trying to automate the recycle also failed when applying the 'Action IIS Application Pool' setting with 'recycleAppPool'.

Information

Error message

Error Code: ERROR_FILE_IN_USE More Information: Web Deploy cannot modify the file 'Microsoft.Data.SqlClient.SNI.x86.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: The process cannot access the file because it is being used by another process.

Solution

  • For those who aren't using the Azure App Service yet.

          - task: IISWebAppManagementOnMachineGroup@0
            displayName: Stop AppPool
            inputs:
              IISDeploymentType: 'IISApplicationPool'
              ActionIISApplicationPool: 'StopAppPool'
              StartStopRecycleAppPoolName: '$(AppPoolName)'  
    

    [deploy application here]

          - task: IISWebAppManagementOnMachineGroup@0
            displayName: Start AppPool
            inputs:
              IISDeploymentType: 'IISApplicationPool'
              ActionIISApplicationPool: 'StartAppPool'
              StartStopRecycleAppPoolName: '$(AppPoolName)'
    

    More information: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/iis-web-app-management-on-machine-group?view=azure-devops