1

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.
Bart VdA
  • 578
  • 1
  • 5
  • 15

2 Answers2

4

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

pembr
  • 56
  • 3
0

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

You could add two task, a stop app service task before deployment and a start app service task after the deployment:

enter image description here

- task: AzureAppServiceManage@0
  displayName: 'Stop Azure App Service: tomsun'
  inputs:
    azureSubscription: 'xxxx'
    Action: 'Stop Azure App Service'
    WebAppName: xxxx


- task: AzureAppServiceManage@0
  displayName: 'Stop Azure App Service: tomsun'
  inputs:
    azureSubscription: 'xxxx'
    Action: 'Restart Azure App Service'
    WebAppName: xxxx

And you could also try to configure the appOffline rule in the publishing profile (.pubxml). Add the EnableMSDeployAppOffline element to the PropertyGroup like this:

<PropertyGroup>
  <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>

Please check this document ERROR_FILE_IN_USE and this thread for some more details.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • I need a YAML solution, not a classic interface solution. We also using Web deploy without .pubxml file. – Bart VdA Sep 20 '21 at 15:50
  • @BartVdA, Just try to convert the stop and restart app service task to the YAML, check the updated answer. – Leo Liu Sep 22 '21 at 03:09
  • @LeoLiu-MSFT one would think when you deploy a fresh build to an app service via CD then it would transparently stop/start. Today that came back to bite me, my web app was still referencing an old copy of a dll & I just couldn't understand why things were working fine on dev but not on qa. stop/start fixed the issue on qa. Not sure why I didn't see this issue in any of my previous deployment – Sangeet Agarwal Apr 15 '22 at 18:23