locked
Add multiple projects programatically into visual studio solution? RRS feed

  • Question

  • How to add multiple projects into visual studio solution programatically?

    By using

    Solution.addFromTemplate(template1);

    Solution.addFromTemplate(template2);

    It overwrites template1 so only project with template1 gets created.

    Tuesday, January 14, 2014 6:24 AM

Answers

  • Set the optional 4th parameter (aka the bool Exclusive parameter), to false to ensure the project is added to the existing solution, and not a new one.

    Sincerely,


    Ed Dore

    Tuesday, January 14, 2014 8:20 PM
  • It shouldn't overwrite because the second optional parameter named Exclusive is false by default, so projects are accumulated. I have tried this macro in VS 2010 and it adds the two projects to the solution:

            Dim sol2 As EnvDTE80.Solution2
            Dim template As String

            Try
                sol2 = CType(DTE.Solution, EnvDTE80.Solution2)

                template = sol2.GetProjectTemplate("ClassLibrary", "VisualBasic")

                DTE.Solution.AddFromTemplate(template, System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "kk1", "kk1", False)
                DTE.Solution.AddFromTemplate(template, System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "kk2", "kk2", False)
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show(ex.ToString())
            End Try


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

    Tuesday, January 14, 2014 8:32 PM

All replies

  • Set the optional 4th parameter (aka the bool Exclusive parameter), to false to ensure the project is added to the existing solution, and not a new one.

    Sincerely,


    Ed Dore

    Tuesday, January 14, 2014 8:20 PM
  • It shouldn't overwrite because the second optional parameter named Exclusive is false by default, so projects are accumulated. I have tried this macro in VS 2010 and it adds the two projects to the solution:

            Dim sol2 As EnvDTE80.Solution2
            Dim template As String

            Try
                sol2 = CType(DTE.Solution, EnvDTE80.Solution2)

                template = sol2.GetProjectTemplate("ClassLibrary", "VisualBasic")

                DTE.Solution.AddFromTemplate(template, System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "kk1", "kk1", False)
                DTE.Solution.AddFromTemplate(template, System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "kk2", "kk2", False)
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show(ex.ToString())
            End Try


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

    Tuesday, January 14, 2014 8:32 PM