Skip to content

Commit

Permalink
Fix issue with determining SolutionProject File
Browse files Browse the repository at this point in the history
  • Loading branch information
wgnf committed Sep 24, 2021
1 parent 18e2fe1 commit cbc6392
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/SlnParser/Helper/EnrichSolutionWithProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public void Enrich(Solution solution, IEnumerable<string> fileContents)
if (fileContents == null) throw new ArgumentNullException(nameof(fileContents));

var fileContentsList = fileContents.ToList();
var flatProjects = GetProjectsFlat(fileContentsList).ToList();
var flatProjects = GetProjectsFlat(solution, fileContentsList).ToList();
solution.AllProjects = flatProjects.ToList().AsReadOnly();

var structuredProjects = GetProjectsStructured(fileContentsList, flatProjects);
solution.Projects = structuredProjects.ToList().AsReadOnly();
}

private IEnumerable<IProject> GetProjectsFlat(IEnumerable<string> fileContents)
private IEnumerable<IProject> GetProjectsFlat(Solution solution, IEnumerable<string> fileContents)
{
var flatProjects = new Collection<IProject>();
foreach (var line in fileContents)
ProcessLine(line, flatProjects);
ProcessLine(solution, line, flatProjects);

return flatProjects;
}
Expand All @@ -53,7 +53,10 @@ private static IEnumerable<IProject> GetProjectsStructured(
return structuredProjects;
}

private void ProcessLine(string line, ICollection<IProject> flatProjectList)
private void ProcessLine(
Solution solution,
string line,
ICollection<IProject> flatProjectList)
{
if (!line.StartsWith("Project(\"{")) return;

Expand All @@ -69,7 +72,13 @@ private void ProcessLine(string line, ICollection<IProject> flatProjectList)

var projectTypeGuid = Guid.Parse(projectTypeGuidString);
var projectGuid = Guid.Parse(projectGuidString);
var projectFile = new FileInfo(projectPath);

var solutionDirectory = Path.GetDirectoryName(solution.File.FullName);
if (solutionDirectory == null)
throw new UnexpectedSolutionStructureException("Solution-Directory could not be determined");

var projectFileCombinedWithSolution = Path.Combine(solutionDirectory, projectPath);
var projectFile = new FileInfo(projectFileCombinedWithSolution);

var projectType = _projectTypeMapper.Map(projectTypeGuid);

Expand Down

0 comments on commit cbc6392

Please sign in to comment.