From 73512d8bf1be8b3127dd1bb8bbfaa2d34a6c3c12 Mon Sep 17 00:00:00 2001 From: Patrik Svensson Date: Thu, 6 Aug 2026 14:16:06 +0200 Subject: [PATCH] Ensure appsettings.{env}.json can be found Currently, the ./Seed.json does not find the appsettings files due to the apps configuration base directory is set to `./dev`. The appsettings files are also not copied to the output directory. This PR makes sure that the files are copied to the output directory, and that the base directory for configuration is set to the binary's output directory. --- .../Configuration/GlobalSettingsFactory.cs | 12 +++++++++--- util/SeederUtility/SeederUtility.csproj | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/util/SeederUtility/Configuration/GlobalSettingsFactory.cs b/util/SeederUtility/Configuration/GlobalSettingsFactory.cs index bad0517a4067..cf66f6bd6158 100644 --- a/util/SeederUtility/Configuration/GlobalSettingsFactory.cs +++ b/util/SeederUtility/Configuration/GlobalSettingsFactory.cs @@ -1,4 +1,5 @@ -using Bit.Core.Settings; +using System.Reflection; +using Bit.Core.Settings; using Microsoft.Extensions.Configuration; namespace Bit.SeederUtility.Configuration; @@ -14,10 +15,15 @@ public static GlobalSettings GlobalSettings private static GlobalSettings LoadGlobalSettings() { + var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + ?? Directory.GetCurrentDirectory(); + var configBuilder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) + .SetBasePath(directory) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true) + .AddJsonFile( + $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", + optional: true, reloadOnChange: true) .AddUserSecrets("bitwarden-seeder-utility") .AddEnvironmentVariables(); diff --git a/util/SeederUtility/SeederUtility.csproj b/util/SeederUtility/SeederUtility.csproj index 7ad91c64da1c..744449e33b7f 100644 --- a/util/SeederUtility/SeederUtility.csproj +++ b/util/SeederUtility/SeederUtility.csproj @@ -19,4 +19,13 @@ + + + PreserveNewest + + + PreserveNewest + + +