5
votes

Problem

Getting a deployment error when trying to publish to an Azure Web App from TFS CI. A file is locked and this prevents the build from updating.

Symptoms

  • Publishing manually (Web Deploy publish from within Visual Studio) usually succeeds.
  • Stopping the Web App and publishing allows it to succeed, however this defeats the point of our CI if we need need to stop and start the Web App each time.
  • CI publish to Web roles and Worker roles don't appear to have this issue, we only get it on publishing to Web Apps (formerly Web Sites, the current Azure Portal term is now App Service).
  • Only publishing from a CI build via TFS fails consistently in this way.

Error

Web deployment task failed. (Web Deploy cannot modify the file 'msvcr100.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 information at the link isn't very helpful.

ERROR_FILE_IN_USE Diagnosis – A destination file cannot be overwritten or deleted because it is currently in use. Resolution – Make sure that the destination file is not in use before performing a sync. If you are syncing content to a web site hosted on IIS 7 or later (using the appHostConfig, iisApp, or contentPath providers), consider taking the application offline during the sync by enabling the appOffline rule.

Attempted resolutions

Edit

How to take web app offline while publishing? deals with taking the app offline using the EnableMSDeployAppOffline configuration - unfortunately this config only seems to be supported when doing WebDeploy through Visual Studio (not CI).

2
Did you find a solution for this?General Electric
Didn't find a solution, currently we are publishing this project directly from VS. Thankfully this site is outside our main product build cycle but it means we can't use our CI process at all. Stopping us from moving our main product from Cloud Service to App Service though.Dale
That sucks, I was trying to set up CI using VSTS but I'm getting this error, and manually restarting the app makes no sense as far as CI goesGeneral Electric
check this answer, using a powershell script fixed it for me stackoverflow.com/questions/37234007/…General Electric

2 Answers

2
votes

You can use the Web Deploy v3 in CI to deploy your web app.

In Web Deploy V3, we added support to automatically take an ASP.Net application offline before publishing to it. This is useful if a user wants to ensure that their application does not have a lock on a file (e.g. SQL CE sdf files which only allow one connection to the file at a time) being overwritten, or if they want to ensure that visitors to their site cannot affect the publish process. When the publish process is completed, the App_Offline.htm file will be removed and the site will be online again.

Or you can add a PowerShell script like following to deploy the web app to Azure:

    param($websiteName, $packOutput)

    $website = Get-AzureWebsite -Name $websiteName

    # get the scm url to use with MSDeploy.  By default this will be the second in the array
    $msdeployurl = $website.EnabledHostNames[1]


    $publishProperties = @{'WebPublishMethod'='MSDeploy';
                            'MSDeployServiceUrl'=$msdeployurl;
                            'DeployIisAppPath'=$website.Name;
                            'Username'=$website.PublishingUsername;
                            'Password'=$website.PublishingPassword}

    Write-Output "Stopping web app..."
Stop-AzureWebsite -Name $websiteName

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

Write-Output "Starting web app..."
Start-AzureWebsite -Name $websiteName

Reference from: https://msdn.microsoft.com/en-us/Library/vs/alm/Build/azure/deploy-aspnet5

0
votes

The new "Deploy AzureRM Web App" task has an option to take the app offline which will prevent this error.

See screenshot for checkbox

enter image description here