Skip to content

Commit

Permalink
Pass SolutionFilterName as global property, add some more output.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Jun 21, 2023
1 parent 9f315de commit c0cc4fc
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/SolutionFilterBuilder/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ public Builder(FileInfo input, string output)
_solutionPath = Path.GetFileName(_solutionPath);
}

Environment.SetEnvironmentVariable(SolutionFilterName, solutionFilterName);

Output.WriteLine($"Solution: '{input}'");
Output.WriteLine($"Filter: '{solutionFilterName}'");
Output.WriteLine();

var solution = SolutionFile.Parse(input.FullName);

_projects = LoadProjects(solution)
_projects = LoadProjects(solution, solutionFilterName)
.ExceptNullItems()
.ToArray();

Expand Down Expand Up @@ -122,14 +121,16 @@ private bool ShouldInclude(ProjectInfo projectInfo)

var property = project.GetProperty(IncludeInSolutionFilter);

if (!bool.TryParse(property?.EvaluatedValue, out var include) || !include)
return false;

return true;
return bool.TryParse(property?.EvaluatedValue, out var include) && include;
}

private static IEnumerable<ProjectInfo?> LoadProjects(SolutionFile solution)
private static IEnumerable<ProjectInfo?> LoadProjects(SolutionFile solution, string solutionFilterName)
{
var globalProperties = new Dictionary<string, string>
{
{ SolutionFilterName, solutionFilterName }
};

foreach (var projectReference in solution.ProjectsInOrder)
{
if (projectReference.ProjectType == SolutionProjectType.SolutionFolder)
Expand All @@ -140,7 +141,17 @@ private bool ShouldInclude(ProjectInfo projectInfo)
try
{
Output.WriteLine($"Load: {projectReference.RelativePath}");
projectInfo = new ProjectInfo(projectReference, new Project(projectReference.AbsolutePath));

var project = new Project(projectReference.AbsolutePath, globalProperties, null);

var filterName = project.GetProperty(SolutionFilterName)?.EvaluatedValue;

if (filterName != solutionFilterName)
throw new InvalidOperationException($"The property {SolutionFilterName} is not set for the project");

Output.WriteLine($" - {IncludeInSolutionFilter}: {project.GetProperty(IncludeInSolutionFilter)?.EvaluatedValue}");

projectInfo = new ProjectInfo(projectReference, project);
}
catch (Exception ex)
{
Expand Down

0 comments on commit c0cc4fc

Please sign in to comment.