.Net,  Microsoft

The world of Dotnet Templates

I have long been using templates for dotnet new and of course Visual Studio. So I’ve started down the road of creating my own templates… or a least trying to understand how to create these,

Now creating templates for dotnet new and especially for Visual Studio has never been a simple task. But let us try.

The first matter is understanding where templates live. For the most part these are based on your user for your PC. This found by using a PS command:

join-path -Path $env:USERPROFILE -ChildPath .templateengine

This will return C:\Users\<your user name>\.templateengine   And as you guess it, there is a .templateengine directory in your users directory. What does that mean, well simply put, when one does a .dotnet new –install, application templates get installed for your user. These actually live in that directory space. Simple enough.

When you start developing your own templates, you need to be careful, because the list of templates can get very long. That may or may not be a problem.
A handy PS script to clear out installed templates and put it back to the original set of templates:

function Reset-Templates{
    [cmdletbinding()]
    param(
        [string]$templateEngineUserDir = (join-path -Path $env:USERPROFILE -ChildPath .templateengine)
    )
    process{
        'resetting dotnet new templates. folder: "{0}"' -f $templateEngineUserDir | Write-host
        get-childitem -path $templateEngineUserDir -directory | Select-Object -ExpandProperty FullName | remove-item -recurse
        &dotnet new --debug:reinit
    }
}

Keep in mind, this clears out all templates you have installed under your user. Use with care. If you have a set of favorite templates… yeap, they will get cleared off too!

Now, where to start? I would go to Sayed’s GitHub repo @

It’s a long read, but one can also go over to Channel9 and look for the video series that steps one through the process.

Another handy resource to search for templates is a web site:

 

Enjoy
~ScottGeek

Leave a Reply