Reload ASP.NET Core app when dll files change (bin deploy)

from:https://stackoverflow.com/questions/52204892/reload-asp-net-core-app-when-dll-files-change-bin-deploy

Environment: ASP.NET Core 2.1, Ubuntu.

In old style ASP.NET, when I did a bin deploy (uploaded some dll files for example), the webapp would detect that and reload itself - very useful.

With Core it doesn't do that. I need to stop and restart the dotnet MyApp.dll process.

How do I make it detect changes to binaries and reload?

------------

There are file watchers in Ubuntu that can issue restart commands whenever files are changed like systemd or inotify, but I would strongly advise against that. Uploads can pause or be slow and when uploading 50 files imagine restart after every single one every couple seconds. Server has no way to know when you have finished uploading last DLL. IIS has same problem, it's reliable in development because you refresh the page after the full DLL rebuild. But when in production you don't want random visitors to boot your site midway while it's still uploading. Errors, file locks, all kinds of weirds things can happen.

As pointed by Chris Pratt you want to script your deployment workflow. Idk what environment you are developing on, but if you have Visual Studio and WinSCP it's as easy as writing couple lines of code with Scripting and Task Automation.

Then your publish workflow can be for example as following:

  1. Hit publish in Visual Studio
  2. VS will execute winscp script after publish is finished
    • Authenticate on remote server
    • Upload publish folder to a remote folder
    • Remove old files
    • Prune logs
    • After all done issue systemctl restart kestrel-myapp command
  3. Then your site is deployed, cleaned and restarted in the most reliable fashion with a single click.
posted @ 2022-09-22 11:15  Yaoquan.Luo  阅读(39)  评论(0编辑  收藏  举报