create helper classes
This commit is contained in:
24
DotNetSolutionTools.Core/Common/CsprojHelper.cs
Normal file
24
DotNetSolutionTools.Core/Common/CsprojHelper.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.Build.Construction;
|
||||
|
||||
namespace DotNetSolutionTools.Core.Common;
|
||||
|
||||
public static class CsprojHelper
|
||||
{
|
||||
public static string[] RetrieveAllCSharpProjectFullPathsFromFolder(string solutionFolderPath)
|
||||
{
|
||||
// if solutionFolderPath does not end with a slash, add one
|
||||
if (solutionFolderPath[^1] != Path.DirectorySeparatorChar)
|
||||
{
|
||||
solutionFolderPath += Path.DirectorySeparatorChar;
|
||||
}
|
||||
var csprojList = Directory.GetFiles(solutionFolderPath, "*.csproj", SearchOption.AllDirectories);
|
||||
return csprojList;
|
||||
}
|
||||
|
||||
public static string[] RetrieveAllCSharpProjectFullPathsFromSolution(SolutionFile solution)
|
||||
{
|
||||
var result = SlnHelper.GetCSharpProjectObjectsFromSolutionFile(solution);
|
||||
var csprojList = result.Select(x => x.FullPath).ToArray();
|
||||
return csprojList;
|
||||
}
|
||||
}
|
||||
23
DotNetSolutionTools.Core/Common/SlnHelper.cs
Normal file
23
DotNetSolutionTools.Core/Common/SlnHelper.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.Build.Construction;
|
||||
|
||||
namespace DotNetSolutionTools.Core.Common;
|
||||
|
||||
public static class SlnHelper
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user