From 14413f62a739c9a9dac29672db82246db446b89e Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Sat, 29 Jan 2022 11:49:38 -0600 Subject: [PATCH] properly sent content root on macos --- ErsatzTV/ErsatzTV.csproj | 6 ------ ErsatzTV/Program.cs | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ErsatzTV/ErsatzTV.csproj b/ErsatzTV/ErsatzTV.csproj index 45a573ac0..5a8329666 100644 --- a/ErsatzTV/ErsatzTV.csproj +++ b/ErsatzTV/ErsatzTV.csproj @@ -10,12 +10,6 @@ - - - Always - - - diff --git a/ErsatzTV/Program.cs b/ErsatzTV/Program.cs index db1ee2527..a9859176b 100644 --- a/ErsatzTV/Program.cs +++ b/ErsatzTV/Program.cs @@ -11,23 +11,22 @@ namespace ErsatzTV { public class Program { + private static readonly string BasePath; + static Program() { - var executablePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; - var executable = Path.GetFileNameWithoutExtension(executablePath); + string executablePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; + string executable = Path.GetFileNameWithoutExtension(executablePath); IConfigurationBuilder builder = new ConfigurationBuilder(); - if ("dotnet".Equals(executable, StringComparison.InvariantCultureIgnoreCase)) - { - builder = builder.SetBasePath(Path.GetDirectoryName(typeof(Program).Assembly.Location)); - } - else - { - builder = builder.SetBasePath(Path.GetDirectoryName(executablePath)); - } + BasePath = Path.GetDirectoryName( + "dotnet".Equals(executable, StringComparison.InvariantCultureIgnoreCase) + ? typeof(Program).Assembly.Location + : executablePath); Configuration = builder + .SetBasePath(BasePath) .AddJsonFile("appsettings.json", false, true) .AddJsonFile( $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", @@ -67,7 +66,8 @@ namespace ErsatzTV .ConfigureWebHostDefaults( webBuilder => webBuilder.UseStartup() .UseConfiguration(Configuration) - .UseKestrel(options => options.AddServerHeader = false)) + .UseKestrel(options => options.AddServerHeader = false) + .UseContentRoot(BasePath)) .UseSerilog(); } }