aspnetcore: Deployment fails due to file in use

Copy of issue #694, because it was closed even though this problem is still unresolved and @Eilon ignores comments that it’s still unresolved.

By @pekkah:

Any workaround for this problem when deploying to Azure web site from VSO build server vNext?

Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'AspNet.Loader.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.

I tried adding a restart azure website command before the deployment but this seems to be still creeping in too often.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 19
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@shirhatti - Here’s an entire thread of people telling you that app_offline doesn’t work, without extensive manual intervention:

#3793

It seems these two are duplicates, and this is a clone of an older, unsolved issue.

I’ve been getting it repeatedly while trying to update our first 2 services in Azure, so Azure isn’t a magical fix either.

Can we expect any progress on this? Our company is looking to pivot to microservices right now, and we’ve got pressures to move to node.js because “.Net Core isn’t mature” - issues like this don’t help me make my case for preserving our current .Net based workflows.

If I’m publishing a .Net Core code, using Microsoft tools (Visual Studio), to a Microsoft platform (Azure) - I shouldn’t be facing UX issues like this if you’re serious about building a leading-class development platform.

These are the kind of issues I expect from Eclipse IDE + Java a decade ago, not Visual Studio and .Net Core in 2019

I provide some help on a community forum and, occasionally, there are people complaining about how ASP.NET Core is advertised as a modern framework and all, and then its publishing story is sub-optimal. And they’re absolutely right.

By design, ASP.NET Core locks file in use.

@shirhatti And that’s fine, but you’ll seriously have to consider a solution for us IIS people who want to achieve 0 downtime when updating our application. Not everyone lives in the Azure part of town and I don’t want to be considered as a second-class citizen.

Here’s a suggestion: support deployment slots in ASP.NET Core Module.

And this is how it might work:

  • Connect to your website via FTP;
  • Create two directories in the website root, named SlotA and SlotB;
  • Publish you application files to the SlotA subdirectory, along with its web.config file;
  • Publish another web.config in the root directory. Here’s how it might look, it describes two deployment slots:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV3" resourceType="Unspecified" />
      </handlers>
      <aspNetCore>
         <slots>
            <slot name="Production" path="SlotA" match="https://www.example.org" />
            <slot name="Staging" path="SlotB" match="https://staging.example.org" />
         </slots>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>
  • The ASP.NET Core Module can now handle multiple applications. For one, it starts the application in the SlotA subdirectory and routes requests for www.example.org to it.
  • Now publish an updated version of the application to SlotB. The ASP.NET Core module notices a change in the directory and starts this application as well, and routes requests for staging.example.org to it;
  • And finally, publish an updated version of the web.config in the root directory. The slots have been swapped like this. SlotB has now become Production.
         <slots>
            <slot name="Production" path="SlotB" match="https://www.example.org" />
            <slot name="Staging" path="SlotA" match="https://staging.example.org" />
         </slots>
  • The ASP.NET Core Module notices the slots configuration has been swapped and, instead of restarting the applications, it just starts to route request for www.example.org to SlotB, while previously they were routed to SlotA.

And that’s it. I can then script some commands to publish a app_offline.htm to the slot I want to update, then remove it, then update the web.config in the root to swap slots.

To improve it even further, each slot element could containt some configuration that stick to the slot, used to define enviroment variables like “CONNECTION_STRING”.