add stuff

This commit is contained in:
Matt Parker [SSW]
2025-01-10 19:52:28 +10:00
parent 5230fedfd0
commit 614893bf1a
3 changed files with 58 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
namespace SharpIDE.Application.Features.SolutionDiscovery;
public class Folder
{
public required string Name { get; set; }
public List<Folder> Folders { get; set; } = [];
public List<MyFile> Files { get; set; } = [];
}
public class MyFile
{
public required string Name { get; set; }
}

View File

@@ -1,12 +1,40 @@
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Globbing;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public static class GetNodesInSolution
{
private static readonly ProjectCollection _projectCollection = new();
public static SolutionFile? ParseSolutionFileFromPath(string solutionFilePath)
{
var solutionFile = SolutionFile.Parse(solutionFilePath);
return solutionFile;
}
public static List<ProjectRootElement> GetCSharpProjectObjectsFromSolutionFile(SolutionFile solutionFile)
{
var projectList = solutionFile
.ProjectsByGuid.Where(x => x.Value.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
.Select(s => ProjectRootElement.Open(s.Value.AbsolutePath))
.ToList();
return projectList;
}
public static List<FileInfo> GetFilesInProject(string projectPath)
{
var project = _projectCollection.LoadProject(projectPath);
var compositeGlob = new CompositeGlob(project.GetAllGlobs().Select(s => s.MsBuildGlob));
var directory = new DirectoryInfo(Path.GetDirectoryName(projectPath)!);
var files = directory.EnumerateFiles("*", SearchOption.AllDirectories)
.Where(f =>
{
var relativeDirectory = Path.GetRelativePath(directory.FullName, f.FullName);
return compositeGlob.IsMatch(relativeDirectory);
})
.ToList();
return files;
}
}