ENVDTE - Add new project to existing solution and locate it in a specific folder

前端 未结 1 1735
北荒
北荒 2021-01-14 13:16

I wrote a Visual Studio Wizard Template using c# on visual studio 2012.

I followed the MSDN steps: I created a VS template, then I created a Class Library project wi

相关标签:
1条回答
  • 2021-01-14 13:42

    You can accomplish this using SolutionFolder interface:

    Project project = getSolutionSubFolder(solution, "SubFolderName");
    if (project != null)
    {
        SolutionFolder folder = (SolutionFolder)project.Object;
        folder.AddFromFile("yourProjectFilePath");
    }
    

    Where getSolutionSubFolder method looks like this:

    private static Project getSolutionSubFolder(Solution2 solution, string subfolder)
    {
        return 
            solution
                .Projects
                .Cast<Project>()
                .FirstOrDefault(
                p => string.Equals(p.Name, subfolder, StringComparison.Ordinal));
    }
    
    0 讨论(0)
提交回复
热议问题