C # EnvDTE Moving projects from the Solution to SolutionFolder
Asked Answered
L

1

10

It is necessary to move the project from the Solution to SolutionFolder. I am trying to remove the project from the solution and add it back into the folder using EnvDTE SolutionFolder.AddFromFile(Filepath line); because not found in the documentation how move projects in the solution (or install a new parent for project). But with the addition of projects in such a way in MRU list(start page, and windows start menu)appear this projects.

How to move a project to SolutionFolder without adding to MRU list?

sry for bad english

adding function as it is at this moment:

protected Project AddProjectToSolutionFolder(Project project1, SolFolderTypes solutionFolderType)
{
    try
    {
        Solution2 solution = (Solution2)((DTE2)base._dteObject).Solution;

        string projFullname = project1.FullName;

        string solutionFolderName = solutionFolderType == SolFolderTypes.Folder1 ? "Folder1" : "Folder2";

        Project project = GetSolutionSubFolder(solution, solutionFolderName);

        if (project != null)
        {
            SolutionFolder folder = (SolutionFolder)project.Object;
            solution.Remove(project1);
            project1 = folder.AddFromFile(projFullname);
        }
    }
    catch (Exception e)
    {
    }
    return project1;
}

private static Project GetSolutionSubFolder(Solution2 solution, string subfolder)
{
    Projects projects = solution.Projects;
    Project folder = projects.Cast<Project>().FirstOrDefault(p => string.Equals(p.Name, subfolder));

    if (folder == null)
        folder = solution.AddSolutionFolder(subfolder);

    return folder;
}
Lungki answered 15/12, 2016 at 7:56 Comment(0)
C
2

SolutionFolder and Project Class don't provide a method to move the include project in solution to solution folder without remove project.

If the project is include in your solution, you need to remove it and add it to solution folder.

Cimbalom answered 16/12, 2016 at 10:48 Comment(1)
Do you mean it will remove Startup project?Cimbalom

© 2022 - 2024 — McMap. All rights reserved.