@Manya, Welcome to Microsoft Q&A, you could find the folder firstly in the solution and get the subproject of the folder.
Here is a code example you could refer to.
static void Main(string[] args)
{
DTE dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.17.0"); // Replace "17.0" with your version of Visual Studio
string solutionPath = dte.Solution.FileName;
string folderPath = Path.Combine(Path.GetDirectoryName(solutionPath), "Test"); // Replace "Test" with your own folder name
foreach (Project item in dte.Solution)
{
if(item.Kind== ProjectKinds.vsProjectKindSolutionFolder)
{
var innerProjects = GetSolutionFolderProjects(item);
foreach (var innerProject in innerProjects)
{
Console.WriteLine( innerProject.Name);
}
}
}
}
private static IEnumerable<Project> GetSolutionFolderProjects(Project project)
{
List<Project> projects = new List<Project>();
var y = (project.ProjectItems as ProjectItems).Count;
for (var i = 1; i <= y; i++)
{
var x = project.ProjectItems.Item(i).SubProject;
var subProject = x as Project;
if (subProject != null)
{
projects.Add(subProject);
//Carried out work and added projects as appropriate
}
}
return projects;
}
Result:(Test folder has two projects)
Hope my solution could help you.
Best Regards,
Jack
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.