diff --git a/util/SeederUtility/Commands/IndividualArgs.cs b/util/SeederUtility/Commands/IndividualArgs.cs
index 5484bb49757c..95b04f236a66 100644
--- a/util/SeederUtility/Commands/IndividualArgs.cs
+++ b/util/SeederUtility/Commands/IndividualArgs.cs
@@ -34,7 +34,7 @@ public class IndividualArgs : IArgumentModel
public bool SelfHosted { get; set; }
[Option("account-age-days", Description = "Backdate the account's CreationDate by N days (default: 0 = today)")]
- public int AccountAgeDays { get; set; }
+ public int? AccountAgeDays { get; set; }
[Option("mangle", Description = "Enable ID mangling for test isolation")]
public bool Mangle { get; set; }
@@ -82,6 +82,6 @@ public void Validate()
Password = Password,
KdfIterations = KdfIterations,
SelfHosted = SelfHosted,
- AccountAgeDays = AccountAgeDays
+ AccountAgeDays = AccountAgeDays ?? 0
};
}
diff --git a/util/SeederUtility/Configuration/GlobalSettingsFactory.cs b/util/SeederUtility/Configuration/GlobalSettingsFactory.cs
index bad0517a4067..1bd211cb9b1b 100644
--- a/util/SeederUtility/Configuration/GlobalSettingsFactory.cs
+++ b/util/SeederUtility/Configuration/GlobalSettingsFactory.cs
@@ -1,5 +1,6 @@
using Bit.Core.Settings;
using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
namespace Bit.SeederUtility.Configuration;
@@ -14,18 +15,22 @@ public static GlobalSettings GlobalSettings
private static GlobalSettings LoadGlobalSettings()
{
- var configBuilder = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true)
- .AddUserSecrets("bitwarden-seeder-utility")
- .AddEnvironmentVariables();
+ // The generic host only reads DOTNET_ENVIRONMENT, while the rest of the repo keys off
+ // ASPNETCORE_ENVIRONMENT; honor both. The seeder is a local development tool, so fall
+ // back to Development rather than Production so appsettings.Development.json applies.
+ var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
+ ?? Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT")
+ ?? Environments.Development;
- var configuration = configBuilder.Build();
- var globalSettingsSection = configuration.GetSection("globalSettings");
+ var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings
+ {
+ // Resolve appsettings files next to the binary, not the caller's working directory.
+ ContentRootPath = AppContext.BaseDirectory,
+ EnvironmentName = environment,
+ });
var settings = new GlobalSettings();
- globalSettingsSection.Bind(settings);
+ builder.Configuration.GetSection("globalSettings").Bind(settings);
return settings;
}
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
+
+
+