diff --git a/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs b/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs index 0b7a70b1..bb0602d0 100644 --- a/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs +++ b/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs @@ -203,25 +203,12 @@ private CodeGenHelpers.ValueType GetValueType(string value, PropertyType propert } } - private IDictionary GetEnvironmentSettings() - { - var buildToolsEnvFile = GeneratorContext.AdditionalFiles.FirstOrDefault(x => Path.GetFileName(x.Path) == Constants.BuildToolsEnvironmentSettings); - if (buildToolsEnvFile is null) - return new Dictionary(); - - var json = buildToolsEnvFile.GetText().ToString(); - if (string.IsNullOrEmpty(json)) - return new Dictionary(); - - return JsonSerializer.Deserialize(json, new JsonSerializerOptions(JsonSerializerDefaults.General)).Environment; - } - internal IDictionary GetMergedSecrets(SettingsConfig settingsConfig, out bool hasErrors) { if (string.IsNullOrEmpty(settingsConfig.Prefix)) settingsConfig.Prefix = "BuildTools_"; - var env = GetEnvironmentSettings(); + var env = Environment.Environment; var secrets = new Dictionary(); hasErrors = false; foreach (var prop in settingsConfig.Properties) @@ -230,11 +217,15 @@ internal IDictionary GetMergedSecrets(SettingsConfig settingsCon var searchKeys = new List { - prefixKey + $"{Environment.TargetPlatform}_{Environment.BuildConfiguration}_{prefixKey}", + $"{Environment.TargetPlatform}_{prefixKey}", + prefixKey, }; if (settingsConfig.Prefix != _defaultPrefix) { + searchKeys.Add($"{Environment.TargetPlatform}_{Environment.BuildConfiguration}_{_defaultPrefix}_{prefixKey}"); + searchKeys.Add($"{Environment.TargetPlatform}_{_defaultPrefix}_{prefixKey}"); searchKeys.Add($"{_defaultPrefix}{prefixKey}"); } diff --git a/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs b/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs index 4f8ecdca..e294b438 100644 --- a/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs +++ b/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs @@ -22,6 +22,8 @@ public abstract class GeneratorBase : ISourceGenerator protected BuildToolsConfig Config { get; private set; } + protected BuildEnvironment Environment { get; private set; } + public void Execute(GeneratorExecutionContext context) { GeneratorContext = context; @@ -39,6 +41,10 @@ public void Execute(GeneratorExecutionContext context) var json = buildToolsConfig.GetText().ToString(); Config = JsonSerializer.Deserialize(json, ConfigHelper.GetSerializerSettings()); + var buildToolsEnvFile = GeneratorContext.AdditionalFiles.FirstOrDefault(x => Path.GetFileName(x.Path) == Constants.BuildToolsEnvironmentSettings); + json = buildToolsEnvFile.GetText().ToString(); + Environment = JsonSerializer.Deserialize(json, new JsonSerializerOptions(JsonSerializerDefaults.General)) ?? new BuildEnvironment(); + try { Generate();