-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolutionFolderService.cs
More file actions
58 lines (52 loc) · 2.17 KB
/
SolutionFolderService.cs
File metadata and controls
58 lines (52 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using EnvDTE;
using EnvDTE80;
namespace CodingWithCalvin.ProjectRenamifier.Services
{
/// <summary>
/// Service for managing solution folder operations.
/// </summary>
internal static class SolutionFolderService
{
/// <summary>
/// Gets the solution folder that contains the specified project, if any.
/// </summary>
/// <param name="project">The project to find the parent folder for.</param>
/// <returns>The parent solution folder project, or null if the project is at the solution root.</returns>
public static Project GetParentSolutionFolder(Project project)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (project?.ParentProjectItem?.ContainingProject != null)
{
var parent = project.ParentProjectItem.ContainingProject;
// Verify it's actually a solution folder
if (parent.Kind == EnvDTE.Constants.vsProjectKindSolutionItems)
{
return parent;
}
}
return null;
}
/// <summary>
/// Adds a project to the solution, placing it in the specified solution folder if provided.
/// </summary>
/// <param name="solution">The solution to add the project to.</param>
/// <param name="projectFilePath">The full path to the project file.</param>
/// <param name="parentSolutionFolder">The solution folder to add the project to, or null for solution root.</param>
/// <returns>The added project.</returns>
public static Project AddProjectToSolution(Solution solution, string projectFilePath, Project parentSolutionFolder)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (parentSolutionFolder != null)
{
// Add to the solution folder
var solutionFolder = (SolutionFolder)parentSolutionFolder.Object;
return solutionFolder.AddFromFile(projectFilePath);
}
else
{
// Add to solution root
return solution.AddFromFile(projectFilePath);
}
}
}
}