Incorrect folder structure for multiple projects

So, I'm trying to create a Multi Project template, and when I set it up, the folder structure doesnโ€™t work out correctly (not like microsoft does when creating projects), and it messed up things like the Packages and Links folders.

This is the current structure:

Solution Folder -Solution File -Folder (Solution Name) --Packages --References --Project1 Folder --Project2 Folder 

I want it to have the same structure as .NET automatically:

 Solution Folder -Solution File -References Folder -Packages Folder -Project1 Folder -Project2 Folder 

Here is my vstemplate:

 <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup"> <TemplateData> <Name>ASP Solution Template</Name> <Description>This is the Solution Template for ASP Applications</Description> <Icon>__TemplateIcon.ico</Icon> <ProjectType>CSharp</ProjectType> </TemplateData> <TemplateContent BuildOnLoad="true"> <ProjectCollection> <SolutionFolder Name="References"> </SolutionFolder> <SolutionFolder Name="packages"> </SolutionFolder> <ProjectTemplateLink ProjectName="$safeprojectname$"> ASPTemplate\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink ProjectName="$safeprojectname$.ClassLibrary"> ClassLibrary\MyTemplate.vstemplate </ProjectTemplateLink> </ProjectCollection> </TemplateContent> </VSTemplate> 
+4
source share
1 answer

I do not think that you can add solution folders to the parent solutions folder using vstemplates.

However , you can try adding a wizard to your template, which allows you to run your own code when a user creates a project from a template.

Follow the instructions here and here , but basically you are doing something like this:

  • Deploy the IWizard interface in the ClassLibrary project and use EnvDTE80 to create folders:

     public class MyWizard : IWizard { public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { // Pseudo-code var dte = (DTE2)automationObject; var solution = (Solution2)dte.Solution; solution.AddSolutionFolder("References"); } // Default implementations of IWizard here (return true and do nothing's) } 
  • Modify vstemplate to use the wizard:

     <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup"> <TemplateData /> <TemplateContent BuildOnLoad="true" /> <!-- Remove the SolutionFolder elements --> <WizardExtension> <Assembly>CustomWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=fa3902f409bb6a3b</Assembly> <FullClassName>CustomWizard.MyWizard</FullClassName> </WizardExtension> </VSTemplate> 

Then the code should run when creating a project with a new template.

Hope this helps you.

+1
source

Source: https://habr.com/ru/post/1494520/


All Articles