DEV Community

Cover image for Create and Publish a Custom .NET Project Template and Private NuGet to GitLab Package Registry
Ray_Dsz
Ray_Dsz

Posted on

Create and Publish a Custom .NET Project Template and Private NuGet to GitLab Package Registry

Table Of Contents

Introduction

In my previous article, I shared a practical overview of Clean Architecture and the structure we implemented across our applications.

In this follow-up, I’ll walk you through how we turned that structure into a reusable project template. With over 20+ internal applications and a team of 8 developers, we simply can’t afford to build each app from scratch every time. That’s where a project template comes in — speeding up development, enforcing consistency, and avoiding repetitive boilerplate.

Imagine a scenario where team members download NuGet packages independently — possibly pulling in licensed, unvetted, or even unwanted packages. This can lead to compliance issues and unnecessary bloat.

So the next logical step?

Centralize NuGet package management using a private registry, and embed that configuration directly into the project template!

Creating a Project Template Package

If you are new here, I had created a .NET Clean Architecture Template previously. You can check here.

Structure is same as below. Done? Let's start=>

IS Web Template

  • Create a folder structure like this:

    Template / Content/ is-template / your Clean Architecture Solution here

  • Within is-template folder, Create .template.config folder.

  • After this, Create json file within the .template.config called template.json.

  • You can modify the template.json content from below

{
      "$schema": "http://json.schemastore.org/template",
      "author": "Rayson",
      "classifications": [
        "blazor",
    "WebAPI"
      ],
      "name": "Team Architecture project template",
      "description": "Project template to create starter project for .NET Team project",
      "identity": "IS.project.starter",
      "shortName": "is-template",
      "sourceName": "ISWebAppTemplate",
      "tags": {
        "language": "C#",
        "type": "project"
      },
      "symbols": {
        "Framework": {
          "type": "parameter",
          "description": "The target framework for the project.",
          "datatype": "choice",
          "choices": [
            {
              "choice": "net8.0"
            },
            {
              "choice": "net9.0"
          }
          ],
          "defaultValue": "net8.0",
          "replaces": "{TargetFramework}"
        }
      }
    }
Enter fullscreen mode Exit fullscreen mode
  • Now run the below command in cmd (Path should be at root of your .Net Clean Architecture Solution):
dotnet new -i .
Enter fullscreen mode Exit fullscreen mode
  • Now, you can run the below command in cmd to create a project based on template. Below, is-template is the shortName you provided in template.json
dotnet new is-template -n YourNewProject
Enter fullscreen mode Exit fullscreen mode

Optional:

  • Now, if you want this package to be publicly available to all your team member, You can follow the below approach.

    • Prerequisites:
    • GitLab / GitHub - Contributor Access required.
  • I will be using gitlabs, As i have expertise on this. But, Iam pretty sure the same process would be used for github as well.

  • First let's make it secure. We will create a access token for the project. You can create it by going to

    Gitlab -> Your Project Repo -> Settings -> Access token

  • Configure the token as below and create it

gitlab token

  • Copy the token and keep it secure. We need it in next step

  • Open cmd and run the below command:

dotnet nuget add source "https://<gitlab-domain>/api/v4/projects/<project-id>/packages/nuget/index.json" --name is_template_package --username <gitlab-username> --password <access-token>
Enter fullscreen mode Exit fullscreen mode
Note: 
<gitlab-username> - your gitlab username
<project-id> - You can find it in your gitlab project like below
Enter fullscreen mode Exit fullscreen mode

project id

  • Now go back to gitlab repo and got to Deploy -> Package Registry

deploy

  • You should see a is_template_package here.

  • Finally, Run the below commands:

dotnet build -c Release

dotnet pack -c Release -o ./nuget
Enter fullscreen mode Exit fullscreen mode
  • You should see a nuget folder created in root, Which contains a <solution-name>.nupkg file.

  • Once done, Run the below command in cmd:

dotnet nuget push ./nuget/<solution-name>.nupkg --api-key <access-token> --source "https://<gitlab domain>/api/v4/projects/<project-id>/packages/nuget/index.json"
Enter fullscreen mode Exit fullscreen mode
  • The approach what i would suggest is using CI/CD pipeline. This is a yaml file where you add the stages. This will be explained in separate post later.

How to get started

Now that we have set up the private Nuget which is available to team members, How to team members install it?. Follow the below process...

  • Add below nuget resource on your local environment using dotnet command. This will add IS team private nuget repository as one of the source for nuget packages.
dotnet nuget add source "https://<gitlab-domain>/api/v4/projects/<project-id>/packages/nuget/index.json"
Enter fullscreen mode Exit fullscreen mode
  • Install the IS starter project template using below command
dotnet new install <nupkg-name>
Enter fullscreen mode Exit fullscreen mode
  • Create new project using below command. Replace with the choice of your project name.
dotnet new is-template -n <solution name>
Enter fullscreen mode Exit fullscreen mode

Example: dotnet new is-starter-web -n TravelDesk this will create solution as TravelDesk.sln and replace the projects name with the given name.

Update template

  • Run the below command to update the template
dotnet new update
Enter fullscreen mode Exit fullscreen mode
  • If you wish to check if there are any updates to the template run the below command
dotnet new update --check-only
Enter fullscreen mode Exit fullscreen mode

Uninstall/Remove template

  • If you want to remove the template from your machine run the below command.
dotnet new uninstall <nuget-name>
Enter fullscreen mode Exit fullscreen mode

Creating a Nuget Package

In order to create a centralised Nuget Package manager, We have to create a console application.

  • Open VS 2022, Select Create a new Project -> Console App
  • Remove the Default Class created.
  • Install all necessary packages that are required for all the projects here. This will be the single point of access for all packages.
  • Your final solution should look like this

nuget solution

Note, In the above image, The yml file was created by me and the nuget folder will be visible, Once you finish the below process.

  • Once done, Follow the same process from this section.
  • Once you got the source gitlab url from the process. The source url would be in this format:
https://<gitlab-domain>/api/v4/projects/<project-id>/packages/nuget/index.json
Enter fullscreen mode Exit fullscreen mode
  • Go to the default template that we created before this section. Open the template solution in vs 2022.
  • Right Click Solution -> Manage NuGet Packages for Solution
  • Click on the Settings (Gear Icon) -> Add new item (+ icon)

Nuget

  • Give package source name and Source as the gitlab url in format:
https://<gitlab-domain>/api/v4/projects/<project-id>/packages/nuget/index.json
Enter fullscreen mode Exit fullscreen mode
  • Remove everything except this.
  • You can follow the process of packaging the template again by checking here and this time change the version from 1.0.0 to 1.0.2. You can set it in .csproj file.

*Once done, In your template, You will get an update to IS.Nuget package. Once updated,

  • This is what will be present in Directory.Packages.props.
<PackageVersion Include="IS.Nuget" Version="1.0.2" />
Enter fullscreen mode Exit fullscreen mode

and in all projects except domain within template:

<PackageReference Include="IS.Nuget" />
Enter fullscreen mode Exit fullscreen mode

Note that: The gitlab project repo for both Template and Nuget are maintained separately. They should not be placed under single repo. So, The project id for Nuget and Template would be different. Same goes for Access token as well.

Conclusion

Creating a project template isn’t just about saving time — it’s about enforcing consistency, reducing errors, and scaling development across multiple applications and teams.

By turning your Clean Architecture setup into a reusable .NET template and combining it with a centralized NuGet package registry, you can:

  • Accelerate onboarding for new team members

  • Prevent unauthorized or accidental package usage

  • Ensure all apps follow the same architectural and dependency standards

  • The template now contains a Private Nuget which will have an update everytime you add a new Nuget package into Console app and push it to gitlab private registry.

This approach has helped our team manage 20+ enterprise applications with fewer surprises and better control.

Wait!! There's more..

Have you ever wondered:
"Rayson, can't this process be even cleaner?"

Well... you're absolutely right — I hate running a bunch of manual commands in cmd too.

The good news? We can simplify it further using CI/CD pipelines and environment variables to automate most of these steps.

Stay tuned — in the next post, I’ll show how to streamline this entire workflow with automation, so you can focus more on development and less on setup.

Top comments (0)