diff --git a/src/Host/FSH.Starter.DbMigrator/Program.cs b/src/Host/FSH.Starter.DbMigrator/Program.cs index 3779e3a46d..9f1f9c53a7 100644 --- a/src/Host/FSH.Starter.DbMigrator/Program.cs +++ b/src/Host/FSH.Starter.DbMigrator/Program.cs @@ -46,9 +46,18 @@ await Console.Out.WriteLineAsync(MigratorCommand.HelpText).ConfigureAwait(false); return 0; } - var builder = Host.CreateApplicationBuilder(args); +// In local development (dotnet run), the working directory is the project folder, +// but appsettings.json is linked and copied to the output directory. +// We explicitly load it from AppContext.BaseDirectory so IdentityModule's JwtOptions validate. +builder.Configuration.AddJsonFile(Path.Combine(AppContext.BaseDirectory, "appsettings.json"), optional: true); +builder.Configuration.AddJsonFile(Path.Combine(AppContext.BaseDirectory, $"appsettings.{builder.Environment.EnvironmentName}.json"), optional: true); + +// Re-add environment variables and command line args so they maintain priority over the manually added JSON files. +builder.Configuration.AddEnvironmentVariables(); +builder.Configuration.AddCommandLine(args); + // Fail-fast before option-validation runs at host build time: if the operator // forgot to set DatabaseOptions__ConnectionString, give them a single clear // line they'll actually read rather than a validation exception stack trace.