A different alternative for deploying our apps is to host the ASP.NET Core app as a Windows service. Of course, this is inherently not portable as Windows services are only available, well, on Windows (Windows Docker containers do exist, of course). Anyway, sometimes, especially for simple apps/APIs, this is the best option because you can easily start and stop the service as you like, and easily see whether they are running from the user interface. Let's see how:
- Start by adding the Microsoft.AspNetCore.Hosting.WindowsServices and Microsoft.Extensions.Hosting.WindowsServices NuGet packages.
- Then, modify your Program class like this:
Host
.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureWebHostDefaults(builder =>
{
builder.UseStartup<Startup>();
});
- Then, use dotnet publish to deploy your app to a folder on your machine and then register...