locked
Adding a project to Folder in a Visual Studio Template RRS feed

  • Question

  • I have created a multi project Visual Studio Template following these instructions:

    http://msdn.microsoft.com/en-us/library/ms185308.aspx.

    This works fine and I can see my two projects in Visual Studio when I select my project template from the File-->New Project option.

    I have followed this link http://msdn.microsoft.com/en-us/library/ms185301.aspx and I am able to add new folders to my solution by doing the following in the CustomWizard.

    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
     {     
         _dte = automationObject as _DTE;
     }
    
     public void RunFinished()
     {
         _solution = (Solution2)_dte.Solution;
     
         _solution.AddSolutionFolder("MyFolder1");
         _solution.AddSolutionFolder("MyFolder2");    
     }

    But I want to add a certain project that is in my template under MyFolder1 and add another project that is in my template under MyFolder2.

    At present with the above code my projects will be loaded from the template AND there will be 2 folders created beside them.  I want the projects under the folders.

    How can I do this??

    Thanks for any help you can give :)


    Thursday, May 1, 2014 8:17 AM

Answers

  • Hello,

    I seems find related code and please take the following thread as your reference:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/47bcecb8-2525-4199-8084-49eee54c5e09/how-to-programatically-add-a-c-project-to-a-solution-subfolder

    Use the following code

    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(...)
    
    

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Anna Cc Thursday, May 8, 2014 4:04 PM
    Friday, May 2, 2014 2:00 AM