locked
Template: Create multiple projects in existing solution without create new folder. RRS feed

  • Question

  • I am trying to create a template that will create 2 projects in the existing solution without creating a folder in the existing solution.

    For example:

    C:\Solutions\Solutions.sln

    C:\Solutions\Project1\Project1.csproj

    C:\Solutions\Project2\Project2.csproj

    On Visual Studio Solutions Explorer, right click on solution and add new project. The template should add 2 new projects

    C:\Solutions\Solutions.sln

    C:\Solutions\Project1\Project1.csproj

    C:\Solutions\Project2\Project2.csproj

    C:\Solutions\Project3\Project3.csproj

    C:\Solutions\Project4\Project4.csproj

     

    Currently my template is adding 2 projects to the solutions but with a structure of

    C:\Solutions\Solutions.sln

    C:\Solutions\Project1\Project1.csproj

    C:\Solutions\Project2\Project2.csproj

    C:\Solutions\Noun\Project3\Project3.csproj

    C:\Solutions\Noun\Project4\Project4.csproj

     

    the .vstemplate file I have:

    <?xml version="1.0"?>
    <VSTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Type="ProjectGroup" Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      <TemplateData>
        <Name>Template Pack</Name>
        <Description>Visual Studio 2010 templates</Description>
        <Icon>__Template_small.png</Icon>
        <PreviewImage>__Template_large.png</PreviewImage>
        <ProjectType>CSharp</ProjectType>
        <SortOrder>1000</SortOrder>
        <CreateNewFolder>false</CreateNewFolder>
        <DefaultName>Noun</DefaultName>
        <ProvideDefaultName>true</ProvideDefaultName>
        <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
        <LocationField>Enabled</LocationField>
        <RequiredFrameworkVersion>4.0</RequiredFrameworkVersion>
      </TemplateData>
      <TemplateContent>
        <ProjectCollection>
          <ProjectTemplateLink ProjectName="$safeprojectname$">MyTemplate\MyTemplate.vstemplate</ProjectTemplateLink>
          <ProjectTemplateLink ProjectName="$safeprojectname$.Test">MyTemplate.Test\MyTemplateTest.vstemplate</ProjectTemplateLink>
        </ProjectCollection>
      </TemplateContent>
    </VSTemplate>

    Thanks for your help. :)

    Tuesday, July 27, 2010 6:34 PM

Answers

  • Hello,

    Sorry for misunderstanding you.

    Based on my research, we can't achieve this by this method. And I don't think it make sense. Could you tell me why do you want to do it?

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by sfhoo Thursday, August 5, 2010 1:22 PM
    Monday, August 2, 2010 10:18 AM

All replies

  • Hello,

    You can use the SolutionFolder element to put two projects in one folder, for example:

    <VSTemplate Version="2.0.0" Type="ProjectGroup"  xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      ... ...
      <TemplateContent>
        <ProjectCollection>
          <SolutionFolder Name="MyFolder">
            <ProjectTemplateLink ProjectName="MyProjTemp1">
              MathClassLib1\MyTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="MyProjTemp2">
              MathClassLib2\MyTemplate.vstemplate
            </ProjectTemplateLink>
          </SolutionFolder>
         </ProjectCollection>
       </TemplateContent>
    </VSTemplate>
    

    For more information, please see: How to: Create Multi-Project Templates .

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, July 28, 2010 3:04 AM
  • First of all, thank you for your reply. Actually I don't want to have the Solution Folder at all. I want two projects add to my current solution without any folder except the Project folder itself.
    Wednesday, July 28, 2010 1:49 PM
  • Hello,

    Do you mean you want to add these two projects to one solution without solution foder as following shows:

    Solution 
        |--Project1 
                   |--Project1.csproj
        |--Project2
                   |--Project2.csproj

    If so, you don't need to do any additional steps. Please see following code snippet:

    <VSTemplate Version="2.0.0" Type="ProjectGroup"  xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      <TemplateData>
        <Name>Multi-Project Template Sample</Name>
        <Description>An example of a multi-project template</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>VisualBasic</ProjectType>
      </TemplateData>
      <TemplateContent>
        <ProjectCollection>
          <ProjectTemplateLink ProjectName="My Template Application 1">
            WindowsApp\MyTemplate.vstemplate
          </ProjectTemplateLink>
          <ProjectTemplateLink ProjectName="My Template Application 2">
            ClassLib\MyTemplate.vstemplate
          </ProjectTemplateLink>
        </ProjectCollection>
      </TemplateContent>
    </VSTemplate>
    

    It works fine in my side.

    If I misunderstood you, or you have any comments, please feel free to let me know.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 29, 2010 6:08 AM
  • Ok, let me explain again. I want to add two projects to current solution

    Let say I already have

    Solution 
        |--Project1 
                   |--Project1.csproj
        |--Project2
                   |--Project2.csproj

    And I want to add two projects. So it will look like

    Solution 
        |--Project1 
                   |--Project1.csproj
        |--Project2

                   |--Project2.csproj
        |--Project3
                   |--Project3.csproj
        |--Project4
                   |--Project4.csproj

    it looks right in the Visual Studio IDE with your VSTemplate, but the file structure store in the computer will have

    C:\Solutions\Solutions.sln

    C:\Solutions\Project1\Project1.csproj

    C:\Solutions\Project2\Project2.csproj

    C:\Solutions\[NameYouProvidedWhenYouAddProject]\Project3\Project3.csproj

    C:\Solutions\[NameYouProvidedWhenYouAddProject]\Project4\Project4.csproj

    I do not want the [NameYouProvidedWhenYouAddProject] folder. I want it to show

    C:\Solutions\Solutions.sln

    C:\Solutions\Project1\Project1.csproj

    C:\Solutions\Project2\Project2.csproj

    C:\Solutions\Project3\Project3.csproj

    C:\Solutions\Project4\Project4.csproj

    I hope you understand my example. Thanks

    Thursday, July 29, 2010 1:50 PM
  • Hello,

    Sorry for misunderstanding you.

    Based on my research, we can't achieve this by this method. And I don't think it make sense. Could you tell me why do you want to do it?

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by sfhoo Thursday, August 5, 2010 1:22 PM
    Monday, August 2, 2010 10:18 AM
  • Thanks for the reply.  That's our project requirement. Can you explain why it didn't make sense to you?  I am currently separate the template into two, so that I can achieve the result I want.

    Tuesday, August 3, 2010 2:14 PM
  • Hello Sfhoo,

    In my opinion, if these two project folders are included in one folder, it will be not impacted on your project, and it also easily let customer know they are generated by one project template.

    So I don't know why you want to separate the template foders.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, August 4, 2010 9:39 AM
  • Hi Nancy,

    Wanted to add to this.  I think the confusion here is whether or not there is a containing folder for the solution.  Sfhoo is trying to get the projects to go directly off of the folder with the .sln file in it.  You are saying to him in one post that the template works fine, creating projects off of the solution folder.  But look where your solution .sln file is -- in the parent directory, yes?

    He doesn't wish to separate template folders.  He simply wants to add two new projects to his existing solution, and the template execution stores the projects away in a solution folder instead of having the projects folder off of the folder with the .sln file.

    Hopefully, that makes more sense?  And, is there a way to do it?

    DHume

     

    • Proposed as answer by IqbalC Wednesday, July 22, 2015 11:06 AM
    • Unproposed as answer by IqbalC Wednesday, July 22, 2015 11:06 AM
    Monday, January 17, 2011 11:33 PM
  • Hi,

    Even i am also facing the same issue, Do we have any solution for this ?

    I tried <CreateNewFolder>false<CreateNewFolder> in Root template, but its not working.

    Thanks,

    Iqbal.

    Wednesday, July 22, 2015 11:09 AM
  • I'm hitting the same issue in 2018, it is still not fixed after 10 years after original question :(
    Did you find any workaround?

    Regards, Dmitry

    Friday, July 13, 2018 2:17 PM