Skip to content

Commit

Permalink
Changes how projects are added to the Workspace in Buildalyzer.Work…
Browse files Browse the repository at this point in the history
…spaces to be based on the Solution order, if there is a Solution (#241, eNeRGy164/LivingDocumentation#56)
  • Loading branch information
daveaglick committed Dec 20, 2023
1 parent 19eedd5 commit 47160a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.0.2

- Changes how projects are added to the `Workspace` in Buildalyzer.Workspaces to be based on the Solution order, if there is a Solution (#241, thanks @AndreasKim).

# 6.0.1

- Added the ability to specify an alternate working directory for running the build in the environment options (#233).
Expand Down
19 changes: 15 additions & 4 deletions src/Buildalyzer.Workspaces/AnalyzerManagerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Build.Construction;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -35,18 +36,28 @@ public static AdhocWorkspace GetWorkspace(this IAnalyzerManager manager)
.Where(x => x != null)
.ToList();

// Add each result to a new workspace
// Create a new workspace and add the solution (if there was one)
AdhocWorkspace workspace = manager.CreateWorkspace();

if (!string.IsNullOrEmpty(manager.SolutionFilePath))
{
SolutionInfo solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, manager.SolutionFilePath);
workspace.AddSolution(solutionInfo);

// Sort the projects so the order that they're added to the workspace in the same order as the solution file
List<ProjectInSolution> projectsInOrder = manager.SolutionFile.ProjectsInOrder.ToList();
results = results
.OrderBy(p => projectsInOrder.FindIndex(g => g.AbsolutePath == p.ProjectFilePath))
.ToList();
}

foreach (AnalyzerResult result in results)
// Add each result to the new workspace (sorted in solution order above, if we have a solution)
foreach (IAnalyzerResult result in results)
{
result.AddToWorkspace(workspace);
// Check for duplicate project files and don't add them
if (workspace.CurrentSolution.Projects.All(p => p.FilePath != result.ProjectFilePath))
{
result.AddToWorkspace(workspace);
}
}
return workspace;
}
Expand Down

0 comments on commit 47160a1

Please sign in to comment.