简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM