Name: templating
Owner: .NET Foundation
Description: This repo contains the Template Engine which is used by dotnet new
Created: 2016-06-28 20:54:16.0
Updated: 2018-05-24 08:11:36.0
Pushed: 2018-05-12 15:52:06.0
Homepage: https://docs.microsoft.com/dotnet/
Size: 8690
Language: C#
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This repository is the home for the .NET Core Template Engine. It contains the brains for dotnet new
.
When dotnet 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 process if
, else if
, else
and end if
style statements.
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.
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.
tnet new mvc --help
ASP.NET Web Application (C#)
or: Microsoft
ons:
u|--auth The type of authentication to use
None - No authentication
Individual - Individual authentication
Default: None
ld|--use-local-db Whether or not to use LocalDB instead of SQLite
bool - Optional
Default: false
|--framework
1.0 - Target netcoreapp1.0
1.1 - Target netcoreapp1.1
Default: 1.0
Let's create a new project named “MyAwesomeProject” in the “src/MyProject” directory. This project should be an ASP.NET MVC project with Individual Auth. To create that template
execute dotnet new mvc -n MyAwesomeProject -o src/MyProject -au Individual
. Let's try that now, the result is below.
tnet new mvc -n MyAwesomeProject -o src/MyProject -au Individual
template "MVC Application" created successfully.
The project was successfully created on disk as expected in src/MyProject
. From here, we can run normal dotnet
commands like dotnet restore
and dotnet build
.
We have a pretty good help system built in, including template specific help (for example dotnet new mvc --help
). If you're not sure the syntax please try that,
if you have any difficulties please file a new issue.
Now that we've covered the basics of using dotnew new
, lets move on to info for template authors and contributors.
You can install additional templates that can be used by dotnet new
. See Available templates for dotnet new.
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 of dotnet 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 of dotnet new
, Visual Studio for Mac, Visual Studio, nor any other environment.
If you're authoring templates, or interested in contributing to this repo, then you're likely interested in how to use the latest version of this experience. The steps required are outlined below.
dotnet new
will be preserved. A new command dotnet new3
will be enabled which allows you to create
files with the latest Template Engine.dotnet new3
.For example, here is the result of running dotnet new3 --help
on a Mac (truncated to save space here).
tnet new3 --help
late Instantiation Commands for .NET Core CLI.
e: dotnet new3 [arguments] [options]
ments:
mplate The template to instantiate.
ncated>
install
using the template NuGet packages will need to be on Windows in order to produce the appropriate assets.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 running dotnet new3
process. The steps required to accomplish this are outlined below.
dotnet new3
build to a DEBUG mode.dotnet new3
session.Once “setup” has completed successfully, run the following command.
et new3 --debug:attach {{additonal args}}
By supplying the --debug:attach
argument with any other argument(s) you are running, you are triggering a Console.ReadLine();
request which pauses execution of the Template Engine at an early point in its execution.
Once the engine is “paused”, you have the opportunity to attach a debugger to the running dotnet new3
process.
In the application you are using to attach a debugger…
New3Command.Run()
args.Any(x => string.Equals(x, "--debug:attach", StringComparison.Ordinal)))
// This is the line that is executed when --debug:attach is passed as
// an argument.
Console.ReadLine();
ctrl + alt + p
.Now that you have a debug session attached to your properly configured dotnet new3
process, head back to the command line and hit enter
. This will trigger Console.Readline()
to execute and your proceeding breakpoint to be hit inside the application you are using to debug.
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:
dotnet new3 -i {the path to the folder containing the templates}
dotnet new3 --help
dotnet new3 -h
dotnet new3
dotnet new3 --list
dotnet new3 -l
dotnet new3 mvc -l Lists all templates containing the text "mvc"
dotnet new3 mvc --help
dotnet new3 mvc -h
dotnet new3 MvcWebTemplate --name MyProject --output src --ParameterName1 Value1 --ParameterName2 Value2 ... --ParameterNameN ValueN
dotnet new3 MvcWebTemplate -n MyProject -o src --ParameterName1 Value1 --ParameterName2 Value2 ... --ParameterNameN ValueN
yo aspnet
yo aspnet