diff --git a/Directory.Packages.props b/Directory.Packages.props
index 5d7200bed..e0150beac 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -17,6 +17,7 @@
+
@@ -47,4 +48,4 @@
-
+
\ No newline at end of file
diff --git a/src/BaGetter/BaGetter.csproj b/src/BaGetter/BaGetter.csproj
index 6c79a3575..36e0a7be2 100644
--- a/src/BaGetter/BaGetter.csproj
+++ b/src/BaGetter/BaGetter.csproj
@@ -11,6 +11,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/src/BaGetter/Program.cs b/src/BaGetter/Program.cs
index 6227bd2f4..3d95580b7 100644
--- a/src/BaGetter/Program.cs
+++ b/src/BaGetter/Program.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Threading.Tasks;
using BaGetter.Core;
using BaGetter.Web;
@@ -7,6 +8,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Hosting.WindowsServices;
namespace BaGetter;
@@ -14,7 +16,18 @@ public class Program
{
public static async Task Main(string[] args)
{
- var host = CreateHostBuilder(args).Build();
+ if (WindowsServiceHelpers.IsWindowsService())
+ {
+ // Make sure appsettings.json can be found when running as windows service
+ Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
+ }
+
+ var builder = CreateHostBuilder(args);
+
+ // Support running as a windows service
+ builder.UseWindowsService();
+
+ var host = builder.Build();
if (!host.ValidateStartupOptions())
{
return;