I was publishing an ASP.NET Core application, straight to production, which is a no-no, no-go and got this error, also seen in Figure 1.
Figure 1, publishing to an Azure App Service, straight to production
Severity Code Description Project File Line Suppression State
Error Web deployment task failed. (Unable to perform the operation (“Delete File”)
for the specified directory (“D:\home\site\wwwroot\dotnet2dot1.exe”). This can occur
if the server administrator has not authorized this operation for the user credentials
you are using. Learn more at: http://go.microsoft.com/fwlink
Unable to perform the operation (“Delete File”) for the specified directory
(“D:\home\site\wwwroot\dotnet2dot1.exe”). This can occur if the server administrator
has not authorized this operation for the user credentials you are using. Learn more at:
The error code was 0x80070005.
Access to the path “D:\home\site\wwwroot\dotnet2dot1.exe”; is denied.
(Win32ErrorCode errorCode, String maybeFullPath)
at Microsoft.Web.Deployment.FileEx.Delete(String path)
at Microsoft.Web.Deployment.FilePathProviderBase.Delete(Boolean whatIf)
When you deploy directly to the production slot of an Azure App Service and there is traffic on the app or the assemblies are loaded into the W3WP process, then you can get errors like this. If this happens and you must deploy directly to production then stop and/or recycle the Azure App Service which would unload the assemblies and release any handles preventing the deployment from being successful.
The best case is to create a deployment slot, deploy and test on the slot and then swap once you are ready to go live with it. Here are some articles I wrote about Azure App Service slots:
- Database connection string when swapping between App Servers slots
- Deploy an App Service using Azure PowerShell to a Deployment Slot
- Web Server Logging, IIS logs, deployment slots and swaps
- How to make an App Setting or Connection String sticky
- Configure Visual Studio Team Services in Visual Studio, deploy to Azure App Service
- Staging and testing your Microsoft Azure App Service
This is also a very informative article “Dealing with locked files during deployment”.