Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support projects in solution subfolders #255

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions ProjectConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,54 @@ public static VCConfiguration GetActiveVCConfiguration(Project project)
public static Project GetStartupProject(DTE dte)
{
ThreadHelper.ThrowIfNotOnUIThread();
SolutionBuild solutionBuild = dte.Solution.SolutionBuild;
if (solutionBuild.StartupProjects != null)

// Access startup projects from SolutionBuild
var startupProjects = dte.Solution.SolutionBuild.StartupProjects as object[];

if (startupProjects != null && startupProjects.Length > 0)
{
string startupProjectName = (string)((Array)solutionBuild.StartupProjects).GetValue(0);
// Get the name of the first startup project
string startupProjectName = (string)startupProjects[0];

// Iterate through all projects in the solution to find a matching project
foreach (Project project in dte.Solution.Projects)
{
if (project.UniqueName == startupProjectName)
Project result = FindProjectByNameRecursive(project, startupProjectName);
if (result != null)
{
return project;
return result;
}
}
}

return null; // No startup project found
}

// Helper function to find the project by name recursively
private static Project FindProjectByNameRecursive(Project project, string projectName)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (project.UniqueName.Equals(projectName, StringComparison.OrdinalIgnoreCase))
{
return project;
}

// Handle solution folders
if (project.Kind == EnvDTE.Constants.vsProjectKindSolutionItems)
{
foreach (ProjectItem item in project.ProjectItems)
{
if (item.SubProject != null)
{
Project foundProject = FindProjectByNameRecursive(item.SubProject, projectName);
if (foundProject != null)
{
return foundProject;
}
}
}
}

return null;
}

Expand All @@ -278,9 +314,11 @@ public static Project GetProjectByName(DTE dte, string name)
ThreadHelper.ThrowIfNotOnUIThread();
foreach (Project project in dte.Solution.Projects)
{
if (project.UniqueName == name)
Project result = FindProjectByNameRecursive(project, name);

if (result != null)
{
return project;
return result;
}
}

Expand Down
Loading