Skip to content

Commit

Permalink
Merge pull request #52056 from JoeRobich/slnf-separators
Browse files Browse the repository at this point in the history
Use absolute project paths when loading a Solution Filter
  • Loading branch information
JoeRobich authored Mar 22, 2021
2 parents 9ddf51f + 8f67fdc commit b47625a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static bool TryRead(string filterFilename, PathResolver pathResolver, out
{
using var document = JsonDocument.Parse(File.ReadAllText(filterFilename));
var solution = document.RootElement.GetProperty("solution");
var solutionPath = solution.GetProperty("path").GetString();
// Convert directory separators to the platform's default, since that is what MSBuild provide us.
var solutionPath = solution.GetProperty("path").GetString()?.Replace('\\', Path.DirectorySeparatorChar);

if (!pathResolver.TryGetAbsoluteSolutionPath(solutionPath, baseDirectory: Path.GetDirectoryName(filterFilename), DiagnosticReportingMode.Throw, out solutionFilename))
{
Expand All @@ -40,16 +41,24 @@ public static bool TryRead(string filterFilename, PathResolver pathResolver, out
return false;
}

// The base directory for projects is the solution folder.
var baseDirectory = Path.GetDirectoryName(solutionFilename);

var filterProjects = ImmutableHashSet.CreateBuilder<string>(StringComparer.OrdinalIgnoreCase);
foreach (var project in solution.GetProperty("projects").EnumerateArray())
{
var projectPath = project.GetString();
// Convert directory separators to the platform's default, since that is what MSBuild provide us.
var projectPath = project.GetString()?.Replace('\\', Path.DirectorySeparatorChar);
if (projectPath is null)
{
continue;
}

filterProjects.Add(projectPath);
// Fill the filter with the absolute project paths.
if (pathResolver.TryGetAbsoluteProjectPath(projectPath, baseDirectory, DiagnosticReportingMode.Throw, out var absoluteProjectPath))
{
filterProjects.Add(absoluteProjectPath);
}
}

projectFilter = filterProjects.ToImmutable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public async Task<SolutionInfo> LoadSolutionInfoAsync(

// Load project if we have an empty project filter and the project path is present.
if (projectfilter.IsEmpty ||
projectfilter.Contains(project.RelativePath))
projectfilter.Contains(project.AbsolutePath))
{
projectPaths.Add(project.RelativePath);
}
Expand Down

0 comments on commit b47625a

Please sign in to comment.