From 52d4155b23f7031198af0f709999d97d8eace75b Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Fri, 20 Dec 2024 16:52:11 -0600 Subject: [PATCH] chore: adding MSBuild Props to BuildEnvironment file --- .../Generators/AppSettingsGenerator.cs | 6 +++--- .../Generators/GeneratorBase.cs | 15 --------------- .../Mobile.BuildTools.Core.targets | 1 + .../Tasks/EnvironmentSettingsTask.cs | 8 ++++++-- .../Utils/BuildEnvironment.cs | 2 ++ 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs b/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs index bb0602d0..767a40a9 100644 --- a/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs +++ b/src/Mobile.BuildTools.AppSettings/Generators/AppSettingsGenerator.cs @@ -28,7 +28,7 @@ the code is regenerated. protected override void Generate() { - var settings = ConfigHelper.GetSettingsConfig(ProjectName, Config); + var settings = ConfigHelper.GetSettingsConfig(Environment.ProjectName, Config); if (settings is null || !settings.Any()) return; @@ -64,7 +64,7 @@ protected override void Generate() settingsConfig.Prefix = settingsConfig.Prefix.Trim(); if (string.IsNullOrEmpty(settingsConfig.RootNamespace)) - settingsConfig.RootNamespace = RootNamespace; + settingsConfig.RootNamespace = Environment.RootNamespace; else settingsConfig.RootNamespace = settingsConfig.RootNamespace.Trim(); @@ -239,7 +239,7 @@ internal IDictionary GetMergedSecrets(SettingsConfig settingsCon key = env.Keys.FirstOrDefault(x => x.Equals(searchKey, StringComparison.InvariantCultureIgnoreCase) || - x.Equals($"{BuildConfiguration}_{searchKey}", StringComparison.InvariantCultureIgnoreCase)); + x.Equals($"{Environment.BuildConfiguration}_{searchKey}", StringComparison.InvariantCultureIgnoreCase)); } if (string.IsNullOrEmpty(key)) diff --git a/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs b/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs index e294b438..38557210 100644 --- a/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs +++ b/src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs @@ -10,15 +10,6 @@ namespace Mobile.BuildTools.AppSettings.Generators public abstract class GeneratorBase : ISourceGenerator { protected GeneratorExecutionContext GeneratorContext { get; private set; } - private string _buildConfiguration; - private string _projectName; - private string _targetFrameworkAssembly; - private string _rootNamespace; - - protected string ProjectName => _projectName; - protected string RootNamespace => _rootNamespace; - - protected string BuildConfiguration => _buildConfiguration; protected BuildToolsConfig Config { get; private set; } @@ -28,12 +19,6 @@ public void Execute(GeneratorExecutionContext context) { GeneratorContext = context; - if (!TryGet(context, "MSBuildProjectName", ref _projectName) - || !TryGet(context, "RootNamespace", ref _rootNamespace) - || !TryGet(context, "Configuration", ref _buildConfiguration) - || !TryGet(context, "TargetFrameworkIdentifier", ref _targetFrameworkAssembly)) - return; - var buildToolsConfig = context.AdditionalFiles.FirstOrDefault(x => Path.GetFileName(x.Path) == Constants.BuildToolsConfigFileName); if (buildToolsConfig is null) return; diff --git a/src/Mobile.BuildTools.Core/Mobile.BuildTools.Core.targets b/src/Mobile.BuildTools.Core/Mobile.BuildTools.Core.targets index 54b70749..80d21dcb 100644 --- a/src/Mobile.BuildTools.Core/Mobile.BuildTools.Core.targets +++ b/src/Mobile.BuildTools.Core/Mobile.BuildTools.Core.targets @@ -56,6 +56,7 @@