I'm migrating an ASP.NET Core application from .NET 6 to .NET 8 and deploying it to an IIS server running on an Azure VM. On the VM I installed only the .NET 8 Hosting Bundle. After the migration, my deployment process (using Azure DevOps pipelines with the IIS Web App Deploy task) mostly works, but I’m encountering an intermittent issue: sometimes the release fails while other times it succeeds.
Here’s an excerpt from the release log when it fails:
##[section]Starting: IIS Web App Deploy
...
[command]"...msdeploy.exe" -verb:sync -source:package='C:\azagent\A6\_work\r1\a\temp_web_package_xyz.zip' -dest:contentPath='Default Web Site' -enableRule:AppOffline -useChecksum -enableRule:DoNotDeleteRule
Info: Updating file (Default Web Site\Approval.DAL.dll).
Error: The process '...msdeploy.exe' failed with exit code 4294967295
...
##[error]Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'Approval.DAL.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.
...
Application:
What I've Tried:
My Questions:
What could be causing the intermittent file locking of Approval.DAL.dll when deploying a .NET 8 application via MSDeploy? How can I reliably resolve or work around this issue to ensure all deployments succeed?
Even since Microsoft acknowledged the locking behavior and released the shadow-copying feature of ASP.NET Core web apps on IIS/Windows, you have no good reason not to use it,
https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-net-6-preview-3#shadow-copying-in-iis
Currently .NET locks application binaries when running on Windows making it impossible to replace binaries when the application is still running.