How to update a running asp.net core application on Windows?

I have a Asp.Net Core MVC application running on Windows Server 2008 R2 with IIS. But every time I update this application, I need to manually stop the applicationPool in IIS, and restart the applicationPool after I finish updating the app. Otherwise it will tel me "the xxx.dll is in use by other progress".

Is there any way to make this process easier?


Solution 1:

A workaround For Windows with no down time and I am regularly using is:

  1. Rename running .NET core application dll to filename.dll.backup
  2. Upload the new .dll (web application is available and serving the requests while file is being uploaded)
  3. Once upload is complete recycle the Application Pool. Either Requires RDP Access to server or function to recycle application pool in your hosting control panel.

IIS overlaps the app pool when recycling so there usually isn’t any downtime during a recycle. So requests still come in without every knowing the app pool has been recycled and the requests are served seamlessly with no downtime.

I am still searching for more better method than this..!! :)

January 2022 - for Linux

For Linux, we use Openresty nginx with Lua script to hold (sleep) incoming requests for few seconds until the service running .NET Core or .NET 5 or .Net 6 application restarts and then we release the threads we had hold.

Refer: https://github.com/basecamp/intermission

Solution 2:

Finally I found my anwser:
I just need add a file named app_offline.htm to the IIS web root(not your project wwwroot folder), and remove it after you replace all of your file. due to this issue you may need try both App_Offline.htm or app_offline.htm .

and this will allow you to use FTP client to update

Solution 3:

Opening the web.config file in an editor and saving it will cause the web application to reload, even if you don't change anything. All DLLs should be replaceable, until a user hits the site, causing the web application to start again. I sometimes use that as a workaround.

A more full fledged solution would be to use Web Deploy, either through Visual Studio or by command line. This can take a litte while to set up, but offers more automation.

https://docs.microsoft.com/en-us/aspnet/core/publishing/iis#deploy-the-application-1