有必要将项目从Solution
移至SolutionFolder
。我试图从解决方案中删除项目并使用EnvDTE
SolutionFolder.AddFromFile(Filepath line);
将其添加回文件夹,因为在文档中没有找到如何在解决方案中移动项目(或为项目安装新的父项)。但是,在MRU列表(开始页面和Windows开始菜单)中以这种方式添加项目会出现这个项目。
如何在不添加MRU列表的情况下将项目移至SolutionFolder?
sry for bad english
此时添加功能:
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;
}
答案 0 :(得分:2)
SolutionFolder和Project Class不提供将解决方案中的include项目移动到解决方案文件夹而不删除项目的方法。
如果项目包含在您的解决方案中,则需要将其删除并将其添加到解决方案文件夹中。