Exploring .NET Core CLI and New Project Templates
Command Line Interface (CLI) is a very popular tool is almost all popular frameworks like Yeoman Generator, Angular, and others. It lends developers access to execute commands to create, build, and run projects, restore packages, and so on.
.NET CLI provides a toolset with a handful commands that can be executed from the command line interface to create .NET Core projects, restore dependencies, and build and run projects. Under the wire, Visual Studio 2015/2017 and Visual Studio Code even uses this tool to perform different options taken by the developers from their IDE; for example, to create a new project using .NET CLI, we can run the following command:
dotnet new
It will list down the available templates and the short name that can be used while creating the project.
Here is the screenshot containing the list of project templates that can be used to create/scaffold projects using .NET Core CLI:
And by running the following command, a new ASP.NET Core MVC application will be created:
dotnet new mvc
The following screenshot shows the provisioning of the new MVC project after running the preceding command. It creates the project in the same directory where the command is running and restores all the dependencies:
To install the .NET Core CLI toolset, there are some native installers available for Windows, Linux, and macOS. These installers can install and set up the .NET CLI tooling on your machine and developers can run the commands from the CLI.
Here is the list of commands with their descriptions that are provided in the .NET Core CLI:
Here are some of the project level commands that can be used to add a new NuGet package, remove an existing one, list references, and others:
The following are some common Entity Framework Core commands that can be used to add migration, remove migration, update the database, and so on.
Here are some of the server level commands that can be used to delete the NuGet package from its actual source repository from the machine, add NuGet package into its actual source repository on the machine, and so on:
To run the preceding commands, we can use the tool known as dotnet from the command line and specify the actual command followed by that. When the .NET Core CLI is installed, it is set into the PATH variable in Windows OS and can be accessed from any folder. So, for example, if you are at your project root folder and wanted to restore the dependencies, you can just call the following command and it will restore all the dependencies that have been defined in your project file:
dotnet restore
The preceding command will start restoring the dependencies or project-specific tools, as defined in the project file. The restoration of tools and dependencies are done in parallel:
We can also set the path where packages can be restored by using the --packages argument. However, if this is not specified, it uses the .nuget/packages folder under the system's user folder. For example, the default NuGet folder for Windows OS is {systemdrive}:\Users\{user}\.nuget\packages and /home/{user} for Linux OS, respectively.