V. Dmitriy
V. Dmitriy

Reputation: 205

C # EnvDTE Moving projects from the Solution to SolutionFolder

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;
}

Upvotes: 10

Views: 576

Answers (1)

Zhanglong Wu - MSFT
Zhanglong Wu - MSFT

Reputation: 1660

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.

Upvotes: 2

Related Questions