Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a Visual Studio 2022 .NET 8 template that with multiple projects?

Can anyone please point me in the right direction on how to create a solution template in Visual Studio 2022 that has 8 .NET 8 C# projects?

I've searched but not finding much helpful information. I'm finding stuff for one project or older versions of Visual Studio. I apologize if there is something out there but I'm not uncovering anything helpful.

Thank you!

like image 675
deadheaddeveloper Avatar asked Nov 01 '25 08:11

deadheaddeveloper


1 Answers

First, you need to prepare the template file, export multiple projects in the solution as project templates, and unzip:

  1. Create a new project, search for "C# Project Template", and select the project template;
  2. Configure new projects;
  3. Complete.
  4. Create a folder to store project templates;
  5. Copy the unzipped project template to the folder (the project template folder cannot have special characters);
  6. Right-click the folder where the project template is stored and select "Include in Project";
  7. Search $safeprojectname$ and replace all $safeprojectname$ in the entire solution with $ext_specifiedsolutionname$. $xxxx$ is a template parameter, please refer to the project and item template parameters for details;
  8. Open the MyTemplate.vstemplate file of one of the project templates, modify the TargetFileName, and do the same for other template files;
  9. Open the .csproj file of one of the project templates, modify the ProjectReference, and do the same for other template files;
  10. Right-click the folder where the project template is stored and select "Exclude from Project"; If you don't know which template parameter to use, place the project template parameter anywhere in the code file. After the file is generated, the parameters will be replaced by the corresponding text.
  11. Open the .vstemplate file of Project Template and replace it with the following content. For details, refer to Creating a Multi-Project Template.

<TemplateData>
    <Name>Wp.WPF.Core</Name>
    <Description>Wp.WPF.Core</Description>
    <!--图标-->
    <!--<Icon>pp.ico</Icon>-->
    <ProjectType>CSharp</ProjectType>
    <LanguageTag>C#</LanguageTag>
    <PlatformTag>EIP4.0</PlatformTag>
    <ProjectTypeTag>CSharp</ProjectTypeTag>
</TemplateData>
<TemplateContent>
    <ProjectCollection>
        <ProjectTemplateLink ProjectName="$safeprojectname$.BLL" CopyParameters="true">
            WpWpfCore\WpWpfCoreBllTemplate\MyTemplate.vstemplate
        </ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="$safeprojectname$.DAL" CopyParameters="true">
            WpWpfCore\WpWpfCoreDalTemplate\MyTemplate.vstemplate
        </ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="$safeprojectname$.Model" CopyParameters="true">
            WpWpfCore\WpWpfCoreModelTemplate\MyTemplate.vstemplate
        </ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="$safeprojectname$.UIL" CopyParameters="true">
            WpWpfCore\WpWpfCoreUilTemplate\MyTemplate.vstemplate
        </ProjectTemplateLink>
    </ProjectCollection>
</TemplateContent>

At this point, all configurations and modifications have been completed. Right-click the project and select "Generate" or "Regenerate"

Copy this compressed package to the root directory of the project template of vs. When creating the project, you can find the project by searching for the project name.

For details, please refer to: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-create-multi-project-templates?view=vs-2022

like image 181
Wenbin Geng Avatar answered Nov 03 '25 00:11

Wenbin Geng