Multi-project Visual Studio template with solution folders containing files

余生长醉 提交于 2019-12-06 08:31:56

问题


I'm creating a multi-project template in Visual Studio, and I got the basics up and running quite nicely.

MySolution.vstemplate:

<VSTemplate Version="2.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
   <TemplateData>
      <Name>My standard .NET solution</Name>
      <Description>My standard .NET solution</Description>
      <Icon>myicon.ico</Icon>
      <ProjectType>CSharp</ProjectType>
      <DefaultName>Customer.Project</DefaultName>
      <SortOrder>5000</SortOrder>
  </TemplateData>
  <TemplateContent>
     <ProjectCollection>
        <SolutionFolder Name=".nuget">
            .... here I'd like to link to a few on-disk files to be included ......
        </SolutionFolder> 
        <SolutionFolder Name="Batchjobs">
           <ProjectTemplateLink ProjectName="$safeprojectname$.Batchjob">My batchjob\MyBatchjob.vstemplate</ProjectTemplateLink>
        </SolutionFolder> 
        <SolutionFolder Name="build">
            .... here I'd like to link to a few on-disk files to be included ......
        </SolutionFolder> 
        <SolutionFolder Name="Testing">
             <ProjectTemplateLink ProjectName="$safeprojectname$.IntegrationTests">MyIntegrationTests\MyIntegrationTests.vstemplate</ProjectTemplateLink>
             <ProjectTemplateLink ProjectName="$safeprojectname$.UnitTests">MyUnitTests\MyUnitTests.vstemplate</ProjectTemplateLink>
        </SolutionFolder> 
     </ProjectCollection>
  </TemplateContent>
</VSTemplate>

However: the solution I'm trying to create with the several contained projects in reality also has several solution folders that correspond to on-disk directories and they contain some files; one is for the NuGet stuff, another is config and PowerShell script for our build process, and more.

I haven't been able to find anything online that would show me how to include solution folder and file items in them into my templated output solution. I can easily create solution folders - but it seems I cannot add any files to them in the templating process.....

Or am I missing something really simple here? Any ideas?


回答1:


The VSProjectTemplate don't be able to do this. You just can add SolutionFolders with Projects and Files inside the projects. In my case, i did resolved creating another project in my solution to group that files of solution Folders and then modified my solution to refer the files on the new projects and not from the solution folder, and then exporting the complete solution.

Solution Folder 1
    Project 1.csproj
        File 1.cs
    Project 2.csproj
        File 2.cs

Solution Folder 2
    File 3.cs
    Project 3.csproj
        File 4.cs
    Project 4.csproj
        File 5.cs

I have created a new project named "Project 5" inside the "Solution Folder 2" and then did access files on them.

Solution Folder 2  
    Project 3.csproj
        File 4.cs
    Project 4.csproj
        File 5.cs
    Project 5.csproj
        File 3.cs

This did the template create the all solution folders, projects and files of the solution.



来源:https://stackoverflow.com/questions/28331155/multi-project-visual-studio-template-with-solution-folders-containing-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!