Matech.Sample.Template 1.0.6

dotnet new install Matech.Sample.Template::1.0.6
This package contains a .NET Template Package you can call from the shell/command line.

How to create .Net Visual Studio Multi Projects Solution Template and deploy Nuget Package?

Create Sample Project

To begin with, we create our sample project by going to the folder where we keep our repositories. I am using dotnet CLI with powershell in Windows 10 but you can use different terminals and OS (MACOS, Linux etc.)

PS> mkdir Matech.Sample.Template
PS> cd Matech.Sample.Template

Add some class library projects (Application, Domain, Infrastructure) and Web Api project.

PS Matech.Sample.Template> dotnet new classlib -n Application
PS Matech.Sample.Template> dotnet new classlib -n Domain
PS Matech.Sample.Template> dotnet new classlib -n Infrastructure
PS Matech.Sample.Template> dotnet new webapi -n WebApi

Add Solution item

PS Matech.Sample.Template> dotnet new sln

Add multiple C# projects to a solution Matech.Sample.Template.sln using a globbing pattern (Windows PowerShell only):

PS Matech.Sample.Template> dotnet sln Matech.Sample.Template.sln add (ls -r **/*.csproj)

Add multiple C# projects to a solution using a globbing pattern (Unix/Linux only):

PS Matech.Sample.Template> dotnet sln Matech.Sample.Template.sln add **/*.csproj

You can check dotnet sln.

Matech.Sample.Template Project

Matech.Sample.Template Project

Let's go to the folder where we created our project and add new classes to our project.

Domain will contain all entities, enums, exceptions, interfaces, types and logic specific to the domain layer. If you are interested in Clean Architecture, you can check my public open source solution template for creating a ASP.NET Core Web Api following the principles of Clean Architecture.

namespace Domain.Entities
    using System.Collections.Generic;

    public class City 
        public City()
            Districts = new List<District>();

        public int Id { get; set; }

        public string Name { get; set; }

        public IList<District> Districts { get; set; }
namespace Domain.Entities
    public class District 
        public int Id { get; set; }

        public string Name { get; set; }

        public int CityId { get; set; }
        public City City { get; set; }


Infrastructure layer contains classes for accessing external resources such as file systems, web services, smtp, and so on. These classes should be based on interfaces defined within the application layer.

namespace Infrastructure
    using Domain.Entities;
    using Microsoft.EntityFrameworkCore;

    public class ApplicationDbContext : DbContext
        public DbSet<City> Cities { get; set; }
        public DbSet<District> Districts { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            optionsBuilder.UseSqlServer("Server=<SQLSERVER>; Database=Sample.TemplateDB; User Id = <YOUR_ID>; Password=<YOUR_PASSWORD>; MultipleActiveResultSets=true;");

Prerequisites for Database Migrations

PS Matech.Sample.Template> dotnet tool install --global dotnet-ef
  • Add Domain reference to Infrastructure project

  • Add Application and Infrastructure reference to WebApi project

  • Dependencies

    • Infrastructure
      • Microsoft.EntityFrameworkCore.SqlServer
      • Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
    • WebApi
      • Microsoft.EntityFrameworkCore.Tools

Add initial create for database.

  • --project Infrastructure (optional if in this folder)

  • --startup-project WebApi

  • --output-dir Migrations

PS Matech.Sample.Template> dotnet ef migrations add "SampleMigration" --project Infrastructure --startup-project WebApi --output-dir Migrations

Sample template project is finally ready 😄

Matech.Sample.Template Project

Adding .template.config and testing locally.

The example below demonstrates the file and folder structure of using a template.json to create a template pack. Check the microsoft docs.


Configure your template.json and that's it 😄.

  "$schema": "",
  "author": "ilker Ayti", // author name
  "classifications": [], // Web/MVC/WebApi
  "name": "Matech Sample Template",
  "identity": "Matech.Sample.Template", // Unique identity for Nuget
  "groupIdentity": "Matech.Sample.Template",
  "shortName": "mst", // short name for dotnet new mat creating new project using this template
  "tags": {
    "language": "C#",
    "type": "project"
  "sourceName": "MatechSample",
  "preferNameDirectory": true,
  "sources": [
      "source": "./",
      "target": "./",
      "exclude": [

Let's try our template locally.

PS > dotnet new --install <Project Folder Path>\Matech.Sample.Template

Matech.Sample.Template Project

Create a new project using our local template.

PS> mkdir Test_Local_Sample_Template
PS> cd Test_Local_Sample_Template
PS Test_Local_Sample_Template> dotnet new mst

Project was created 😄


Check the project and if anything is wrong, change the settings you made and install template locally for testing again.

Uninstall Template

PS> dotnet new --uninstall
PS> dotnet new -u <Project Folder Path>\Matech.Sample.Template

Configure Nuget Deployment

First you need to create an account on like my profile ilkerayti.

Download Nuget.exe and add to Path

Actually you don't need to add path Nuget.exe but it is a very useful usage. Download Nuget's latest version. Windows 10 search: Edit the system environment variables.


Go to Environment Variables


Go to System variables Path with double click.


Add New nuget.exe file location in your system.

Path New

Configure .nuspec file

Open terminal in your Matech.Sample.Template project folder

PS Matech.Sample.Template> nuget spec

Package.nuspec file must be created in your project folder.

<?xml version="1.0" encoding="utf-8"?>
<package >
    <authors>ilker Ayti</authors>
    <license type="expression">MIT</license>
    <repository type="git" url="" branch="master" />
    <description>Matech Sample Template for Web Api and .NET Core 3.1.</description>
    <tags>dotnet-core webapi csharp template</tags>
      <packageType name="Template" />
    <file src="**" exclude="**\bin\**\*;**\obj\**\*;**\*.user;**\*.lock.json;**\.DS_Store;**\.git\**\*;**\.github\**\*;**\.vs\**\*;**\*LICENSE;**\*.gitattributes;**\*;**\*.gitignore;**\*nuget.config;" target="/content" />

After the configuration, we finally created a .nupkd file for upload or push.

PS Matech.Sample.Template> nuget pack Package.nuspec -NoDefaultExcludes

If you don't add nuget.exe to Environment System Variable Path just use the nuget.exe

PS Matech.Sample.Template> C:\Nuget\nuget.exe pack Package.nuspec -NoDefaultExcludes

Package was created.


Nuget Package Explorer is very useful tool for checking .nupkd file before publish.


Finally we can upload to packages to Nuget servers 😄

Upload Package




Check Matech.Sample.Template

Sample Template Usage

Open terminal in your repos folder.

PS> mkdir Your.Template.Name
PS> cd Your.Template.Name

Template will use your folder name as project name

PS Your.Template.Name> dotnet new --install Matech.Sample.Template
PS Your.Template.Name> dotnet new mst


If you are having problems, please let us know by raising a new issue.


This project is licensed with the MIT license.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 334 11/10/2021
1.0.5 309 10/10/2021
1.0.4 2,301 1/14/2021
1.0.3 519 9/18/2020
1.0.2 432 9/18/2020
1.0.1 407 9/18/2020
1.0.0 425 9/18/2020