It's Template week! All this week, we're highlighting templates in all their glory.
Why?
Why not!
First off, we're talking the new templating engine in .NET Core.
Jerrie Pelser has a great post on just that!
Tips for developing templates for dotnet new
When creating a new project with the
dotnet new
command, you are offered a list of templates you can use. These templates allow you to quickly bootstrap a new application according to a specific configuration. There are for example templates to create an MVC application, a Razor application, an API etc.You can also install extra templates which have been created by other authors. You can discover these templates on the .NET Templating Wiki or on the dotnet core templates website.
You are also able to develop your own templates, either for internal use, or to make it available on NuGet for other people to take advantage of.
I recently developed templates that allow developers to bootstrap a new application that makes use of Auth0 for authentication.
Here are useful resources I came across, as well as some tips for issues I ran into.
Useful Resources
... [Nope, not going to steal his thunder, click through for this great resource list]
A few issues I ran into
Identity and Group Identity...
Customise parameter names ...
Conclusion
I am very happy about the inclusion of the new .NET Templating engine. It is still a little limited in some senses, but it is a great step forward. I hope to see the community contribute a lot of new templates.
Next is a must read post from Sayed-Ibrahim-Hashimi that takes you from zero to template hero...
How to create your own templates for dotnet new
You can now create your own templates for
dotnet new
. Creating and installing your own templates is an experimental feature at this point, but one that we are seeing significant interest in and that deserves more of your feedback before we enable it for broad use with .NET Core 2.0. The version ofdotnet new
shipped with the .NET Core 1.0 SDK has a new command line parameter--install
. This is an undocumented feature, and is not currently included in the help output.You can try the new template experience if you have the new SDK or Visual Studio 2017 installed. If you didn’t you can right now.
The goal of this post is to connect with developers who are interested in creating templates. If you maintain a library or framework project on GitHub, then you are a great candidate to be a template author. There are lots of other cases too, where creating templates makes sense. If you can create a sample, you can create a template. It’s not hard at all.
In the last update for .NET Core, we have updated
dotnet new
. This new version ofdotnet new
is now built on top of the new Template Engine, which is a library that we are developing. To learn more about how to usedotnet new
see the docs. In this article, we’ll show how to create some custom templates and then use them fromdotnet new
....
Closing
In this post, we have shown how you can get started with creating your own custom templates for
dotnet new
. We are still working on enabling the end user scenarios where templates are acquired and used. In this release, the--install
switch is hidden because it’s currently in preview. The syntax of this command is likely to change. After installing templates, to reset your templates back to the default list you can run the commanddotnet new --debug:reinit
In the following section, you’ll find some links to existing resources. Please share your comments here and file issues as needed. You can also reach me on twitter@SayedIHashimi
We’re very excited to see the awesome templates that the community creates. In addition to this blog, we may postdotnet new
related posts to the .NET Web Developer Blog.
Next up is the current home of the community's dotnet new template gallery, http://dotnetnew.azurewebsites.net/
Here's a 30,000 foot few of all the templates (looks like allot doesn't it? That's because it is!)
Here's another list of available templates for dotnet new, from the official github repo;
Last, but not least, is that offical templating repo, https://github.com/dotnet/templating
Overview
This repository is the home for the .NET Core Template Engine. It contains the brains for
dotnet new
. Whendotnet new
is invoked, it will call the Template Engine to create the artifacts on disk. Template Engine is a library for manipulating streams, including operations to replace values, include/exclude regions and processif
,else if
,else
andend if
style statements.Template Samples
We have created a dotnet template samples repo, which shows how you can use the Template Engine to create new templates. The samples are setup to be stand alone for specific examples. If you are in need of a sample, and it doesn't exist please create an issue in the samples repo.
Info for
dotnet new
usersYou can create new projects with
dotnet new
, this section will briefly describe that. For more info take a look at Announcing .NET Core Tools Updates in VS 2017 RC.To get started let's find out what options we have by executing
dotnet new --help
. The result is pasted in the block below....
What to expect when working with this repo
The instructions below enable a new command at the
dotnet
CLI,dotnet new3
, that uses the bits and templates contained in this repo. Think of it as a "preview" version ofdotnet new
for trying out new switches, interactions and display styles before rolling them in to the product.Commands executed against
dotnet new3
won't impact the behavior ofdotnet new
, Visual Studio for Mac, Visual Studio, nor any other environment....
Debugging
Debugging code requires your current
dotnet new3
session to have its active build session configured to DEBUG, and a debugger from your application of choice to be attached to the current runningdotnet new3
process. The steps required to accomplish this are outlined below....
Installing templates
Templates can be installed from packages in any NuGet feed, directories on the file system or ZIP type archives (zip, nupkg, vsix, etc.) To install a new template use the command:
... [Click through for the rest] ...
Follow @CH9
Follow @coding4fun
Follow @gduncan411
