Skip to content

Commit

Permalink
chore: adding MSBuild Props to BuildEnvironment file
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Dec 20, 2024
1 parent a33ebf3 commit 52d4155
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -239,7 +239,7 @@ internal IDictionary<string, string> 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))
Expand Down
15 changes: 0 additions & 15 deletions src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Mobile.BuildTools.Core/Mobile.BuildTools.Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<EnvironmentSettingsTask ConfigurationPath="$(BuildToolsConfigFilePath)"
ProjectName="$(MSBuildProjectName)"
ProjectDirectory="$(MSBuildProjectDirectory)"
RootNamespace="$(RootNamespace)"
SolutionDirectory="$(SolutionDir)"
Configuration="$(Configuration)"
IntermediateOutputPath="$(IntermediateOutputPath)"
Expand Down
8 changes: 6 additions & 2 deletions src/Mobile.BuildTools.Core/Tasks/EnvironmentSettingsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
namespace Mobile.BuildTools.Tasks;

public class EnvironmentSettingsTask : BuildToolsTaskBase
{
{
public string RootNamespace { get; set; }

[Output]
public ITaskItem[] EnvironmentSettings { get; private set; } = [];
internal override void ExecuteInternal(IBuildConfiguration config)
Expand All @@ -26,7 +28,9 @@ internal override void ExecuteInternal(IBuildConfiguration config)
}

var environment = new BuildEnvironment
{
{
ProjectName = ProjectName,
RootNamespace = RootNamespace,
BuildNumber = CIBuildEnvironmentUtils.BuildNumber,
IsCI = CIBuildEnvironmentUtils.IsCI,
IsAppCenter = CIBuildEnvironmentUtils.IsAppCenter,
Expand Down
2 changes: 2 additions & 0 deletions src/Mobile.BuildTools.Reference/Utils/BuildEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Mobile.BuildTools.Utils
{
public class BuildEnvironment
{
public string ProjectName { get; set; }
public string RootNamespace { get; set; }
public bool IsCI { get; set; }
public bool IsAppCenter { get; set; }
public bool IsAppVeyor { get; set; }
Expand Down

0 comments on commit 52d4155

Please sign in to comment.