none
How to programatically add a C# project to a solution sub-folder

    Question

  • I am using VS2012 to create a customn solution via the New Project wizard.

    I am programatically creating a multi project solution inside an implementation of IWizard.

    In the RunStarted() method, Obtain a reference to my solution from the automationObject parameter like this (simplified snippet):

    {
        DTE2 dte = automationObject as DTE2;
        Solution4 solution = dte.Solution as Solution4;
        Project subProject = solution.AddSolutionFolder("ProjectFolder");
    }
      

    I can do

    solution.AddFromTemplate()


    to add projects to the root level of my solution, and I can do

    testProject.ProjectItems.AddFromTemplate()

    to add Items to the 'ProjectFolder'.

    How can I get my projects into 'ProjectFolder'?

    Thanks in advance

    Paresh


    • Edited by Paresh138 Wednesday, July 17, 2013 10:28 AM
    Wednesday, July 17, 2013 10:26 AM

Answers

  • EnvDTE80.Solution2 solution2;
    EnvDTE.Project projectSolutionFolder;
    EnvDTE80.SolutionFolder solutionFolder;

    solution2 = (EnvDTE80.Solution2) dte.Solution;

    projectSolutionFolder = solution2.AddSolutionFolder("ProjectFolder");

    solutionFolder = (EnvDTE80.SolutionFolder) projectSolutionFolder.Object;

    solutionFolder.AddFromTemplate(...)


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    Wednesday, July 17, 2013 2:32 PM

All replies

  • EnvDTE80.Solution2 solution2;
    EnvDTE.Project projectSolutionFolder;
    EnvDTE80.SolutionFolder solutionFolder;

    solution2 = (EnvDTE80.Solution2) dte.Solution;

    projectSolutionFolder = solution2.AddSolutionFolder("ProjectFolder");

    solutionFolder = (EnvDTE80.SolutionFolder) projectSolutionFolder.Object;

    solutionFolder.AddFromTemplate(...)


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    Wednesday, July 17, 2013 2:32 PM
  • Thanks.

    I tried it with Solution4 as well, since that is what we need to use and it works well.
    Thursday, July 18, 2013 8:19 AM