From 06c76f574538e88715533ceff088c90ec16bafd5 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 29 Jan 2023 04:28:34 +0200 Subject: [PATCH] NetworkResurrector.Server fix --- .../NetworkResurrector.Server/Program.cs | 26 ++++++++++++++----- .../PublishProfiles/FolderProfile.pubxml | 6 ++--- .../appsettings.json | 3 --- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/server/NetworkResurrector.Server/Program.cs b/src/server/NetworkResurrector.Server/Program.cs index 89d21d5..8c9c470 100644 --- a/src/server/NetworkResurrector.Server/Program.cs +++ b/src/server/NetworkResurrector.Server/Program.cs @@ -5,6 +5,8 @@ using Microsoft.Extensions.Hosting; using NetworkResurrector.Server.Extensions; using Serilog; using System; +using System.Diagnostics; +using System.Linq; namespace NetworkResurrector.Server { @@ -12,7 +14,24 @@ namespace NetworkResurrector.Server { public static void Main(string[] args) { - var builder = WebApplication.CreateBuilder(args); + var isConsole = Debugger.IsAttached || args.Contains("--console"); + + WebApplicationBuilder builder; + if (isConsole) + { + builder = WebApplication.CreateBuilder(args); + } + else + { + var webApplicationOptions = new WebApplicationOptions() + { + ContentRootPath = AppContext.BaseDirectory, + Args = args, + ApplicationName = Process.GetCurrentProcess().ProcessName + }; + builder = WebApplication.CreateBuilder(webApplicationOptions); + builder.Host.UseWindowsService(); + } builder.Host.UseSerilog((_, lc) => { @@ -24,11 +43,6 @@ namespace NetworkResurrector.Server }); builder.Services.ConfigureServices(builder.Configuration); - - var useWindowsService = builder.Configuration.GetValue("Host:UseWindowsService"); - if (useWindowsService) - builder.Host.UseWindowsService(); - var app = builder.Build(); app.Configure(); diff --git a/src/server/NetworkResurrector.Server/Properties/PublishProfiles/FolderProfile.pubxml b/src/server/NetworkResurrector.Server/Properties/PublishProfiles/FolderProfile.pubxml index 1d1b2fe..886bdf4 100644 --- a/src/server/NetworkResurrector.Server/Properties/PublishProfiles/FolderProfile.pubxml +++ b/src/server/NetworkResurrector.Server/Properties/PublishProfiles/FolderProfile.pubxml @@ -1,8 +1,8 @@  - + false false @@ -10,7 +10,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU FileSystem - bin\Release\net5.0\publish\ + bin\Release\net6.0\publish\ FileSystem net6.0 diff --git a/src/server/NetworkResurrector.Server/appsettings.json b/src/server/NetworkResurrector.Server/appsettings.json index e9b20da..4868032 100644 --- a/src/server/NetworkResurrector.Server/appsettings.json +++ b/src/server/NetworkResurrector.Server/appsettings.json @@ -3,9 +3,6 @@ "ConnectionStrings": { "DatabaseConnection": "Server=#########;Database=#########;User Id=#########;Password=#########;MultipleActiveResultSets=true" }, - "Host": { - "UseWindowsService": false - }, "Serilog": { "MinimumLevel": { "Default": "Information",