Create new custom project on specified template using .NET Core

Description:

We will try to create new project template like “console”, “web” using .Net Core.

Use case:

You have to write same code in multiple solution files then create project template of that code and reuse everywhere.

Prerequisite:

Steps to create project template

  1. Create class library project and add your custom logic in it.
  2. Need to add template.json file with template confiurationThe template.json file is placed in a .template.config folder in the root directory of the class library. The file provides configuration information to the template engine. The minimum configuration requires the members shown in the following table, which is sufficient to create a functional template.
    {
      "$schema": "http://json.schemastore.org/template",
      "author": "Rahul Jadhav",
      "classifications": [ "Cusotm", "Class", "Library" ],
      "identity": "ClassLibrary.SampleProject",
      "name": "Custom Class Library Project",
      "shortName": "customclasslibrary"
    }
  1. Create nuget package of same using these instructions no need to add package to nuget package gallery. We just need nuget file.  
    Suppose you have created file like ClassLibrary.SampleProject.nupkg

Execute following commands in command prompt:

  1. Now we will add above nuget package in projects list using following command
    dotnet new -i 
    In our case,
    dotnet new -i ClassLibrary.SampleProject.nupkg
You will see ClassLibrary.SampleProject.nupkg Template in Templates list displayed on command prompt after successful installation
  1. Create a empty folder with project_name
    mkdir 
    cd 
  1. Execute dotnet core command to create class library project and give short name of template which we have installed previouslyIn our case it is “customclasslibrary”
    dotnet new customclasslibrary
You will see custom class library project structure is created in newly created folder. Now you don’t have rewrite custom code for every solution your template file has it and it is added by default when we execute above command. If you like above article please like and share it. Thank you :)  

Comments

Popular posts from this blog

Sonarqube Integration with Visual Studio 2022 and VS Code

Run And Debug Test Cases Using Jest With Different CLI Options

Install Kibana as Windows Service Using Powershell