Running ASP.NET Core applications as Windows services with NSSM
Posted: (EET/GMT+2)
You've written a cool ASP.NET Core web application, and now you want to host it on a Windows machine for your colleagues or clients to enjoy. Without running IIS web server, how could you make sure your application runs at all times, even if the server is restarted?
ASP.NET Core applications are run with dotnet.exe, passing in the name of your applications main DLL file as a parameter. For example:
dotnet.exe MyOwnApp.dll
But, running this command when the computer restarts is not trivial. My solution is to use a tool called NSSM, that allows you to convert any Windows application to a Windows service application. NSSM stands for "Non-Sucking Service Manager".
To use NSSM, you would first install NSSM on your computer (there's no actual installation utility, just download the ZIP and extract), and then run the following command:
nssm install MyServiceName
Then, a popup is shown on the screen allowing you to select what application to run. Set "dotnet.exe" as the actual utility to run, and the name of your own application's DLL as an argument to the command. That should do it.
If you need to later change your settings, simply say "nssm edit MyServiceName" on the command-line.
Hope this helps!