Sep
8
How to create a Visual Studio Project Type

Prepare Your Project

Make sure your project is clean and generic:

  • Remove any project-specific code or secrets.
  • Replace specific names with placeholders if needed (e.g., MyCompany.MyLibrary ? TemplateNamespace.MyLibrary).
  • /ul>

    Create a Template Configuration File

    In the root of your project, create a .template.config folder and add a template.json file inside it.

    Example template.json:

    {
      "$schema": "http://json.schemastore.org/template",
      "author": "Your Name or Company",
      "classifications": [ "Library", "C#" ],
      "identity": "YourCompany.ClassLibrary.Template",
      "name": "My Class Library Template",
      "shortName": "myclasslib",
      "tags": {
        "language": "C#",
        "type": "project"
      },
      "sourceName": "TemplateNamespace",
      "preferNameDirectory": true
    }
    • sourceName: This is the placeholder that will be replaced with the project name when the template is used.
    • shortName: This is the command-line shortcut to use the template.
    • /ul>

      Pack the Template

      Use the .NET CLI to pack your template into a .nupkg file:

      dotnet new -i .
      --to distribute
      dotnet pack
      --install locally
      dotnet new -i ./bin/Debug/<your-template>.nupkg

      Use the Template

      Now you can create a new project using your template:

      dotnet new myclasslib -n MyNewLibrary

      Optional: Publish to NuGet

      If you want others to use your template:

      1. Create a NuGet account and API key.
      2. Push your .nupkg file:
      3. /ol>
        dotnet nuget push <your-template>.nupkg -k <your-api-key> -s https://api.nuget.org/v3/index.json


An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.