How to create a custom VS solution template (not project or item template) using visual studio extensions

SaTechyv 6 Reputation points
2023-07-28T18:55:43.7666667+00:00

Hi all,

I want to create a custom solution template with a solution folder and some files in the solution folder. I dont want any project template in the solution.

I remember doing this before but I forgot how I accomplished it.

Can anyone tell me how to create this custome solution template (not project or item template) using Visual Studio Extensibility ?

PLEASE HELP

Thanks in advance

SaTechvy

Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
216 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 30,566 Reputation points Microsoft Vendor
    2023-07-31T07:14:41.42+00:00

    Hello @SaTechyv ,

    Welcome to Microsoft Q&A forum.

    Do you mean creating an empty solution and then add a solution folder and some files?

    If so, VS provides a default empty solution template. You can directly create it from VS, after that you can right-click the solution to add solution folder and files, see following screenshots.

    User's image

    User's image

    Or you mean packaging this custom solution and make it as a Visual Studio extension?

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Karen Payne MVP 35,421 Reputation points
    2023-08-02T09:15:04.15+00:00

    How to create a custom solution template (see also this repository)

    Create the projects, for each project export as a project template.

    Next create a folder that will hold the custom solution template.

    Extract from .zip files each project into the custom solution template folder. Note that each project has a MyTemplate.vstemplate file.

    In the root of the solution folder place a icon file that represents the template that shows up in Visual Studio.

    In the root folder create a new file named root.vstemplate. The contents will tell Visual Studio what to do.

    The first section is pretty much self explanatory while the second section tells Visual Studio what projects to include and to create if desired virtual folders.

    Example folder structure, one test project, two class projects.

    P1

    The solution template

    <VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
        <TemplateData>
            <Name>OED EF Core base solution</Name>
            <Description>Base EF Core solution</Description>
            <Icon>efcore.ico</Icon>
            <ProjectType>CSharp</ProjectType>
        </TemplateData>
    
        <TemplateContent>
    
            <ProjectCollection>
    
                <SolutionFolder Name="Class projects">
    
                    <ProjectTemplateLink ProjectName="DataLibrary">
                        DataLibrary\MyTemplate.vstemplate
                    </ProjectTemplateLink>
    
                    <ProjectTemplateLink ProjectName="ConfigurationHelper">
                        ConfigurationHelper\MyTemplate.vstemplate
                    </ProjectTemplateLink>
                    
                </SolutionFolder>
    
                <SolutionFolder Name="Unit test projects">
                    <ProjectTemplateLink ProjectName="BaseUnitTestProject">
                        BaseUnitTestProject\MyTemplate.vstemplate
                    </ProjectTemplateLink>
                </SolutionFolder>
    
    
            </ProjectCollection>
    
        </TemplateContent>
    </VSTemplate>
    

    Note in this case there is no main project which in this case is intentional but you could add one. Also worth mentioning, say you create a solution template for web which today defaults to an older version of BootStrap 5. Same will happen with your template so you need to consider that. Same goes for NuGet packages.

    Personally I found the above works great but too restrictive and moved to doing this with dotnet cli with batch files. Below is a base prototype which grew into a custom console project with a menu system to allow me to pick and choose project types so do not think too much about this as it was a concept idea.

    @echo off
    
    :: ------------------------------------------------------------
    :: create a solution with a razor pages project and a class library
    :: add Serilog packages and EF Core
    :: add virtualization folders
    :: add a readme.md file
    :: NOTE that the Nuget packages are the latest versions as of 07-2023
    :: ------------------------------------------------------------
    
    md RazorSolution
    cd RazorSolution
    
    :: create solution
    dotnet new sln -n RazorSolution
    
    :: Here we are not using top level statements
    dotnet new webapp -o Demo1 --use-program-main
    
    :: Add Serilog packages
    dotnet add Demo1\Demo1.csproj package  Serilog.AspNetCore -v 7.0.0
    dotnet add Demo1\Demo1.csproj package Serilog.Sinks.Console -v 4.1.0
    
    :: Add Serilog Themes Library by Karen Payne
    dotnet add Demo1\Demo1.csproj package SeriLogThemesLibrary -v 1.0.0.1
    
    :: add virtualization folder
    dotnet sln RazorSolution.sln add Demo1\Demo1.csproj --solution-folder RazorPages
    
    :: add class library
    dotnet new classlib -o DataLibrary
    
    :: add Entity Framework Core package
    dotnet add DataLibrary\DataLibrary.csproj package Microsoft.EntityFrameworkCore.SqlServer -v 7.0.9
    
    :: add virtualization folder for class projects
    dotnet sln RazorSolution.sln add DataLibrary\DataLibrary.csproj --solution-folder "Classes Projects"
    
    cd Demo1
    
    :: add reference to class library
    dotnet add reference ../DataLibrary/DataLibrary.csproj
    
    cd..
    
    :: new file which once open the solution add it to the solution
    echo # About> readme.md
    
    
    pause
    

    You are better off IMHO to keeping with a standard blank solution and add custom projects as outlined at How to create your own templates for dotnet new. So then the templates are in Visual Studio e.g.

    P2

    And from the CLI


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.