I got hit by the flu that has been going around and now that the fever has passed I thought it would be a good time to try out the new version of the Angular template for ASP.NET Core that works well with the Angular CLI.
Template Installation
Note that at the time of this writing the templates are in the release candidate stage and a new version could be available by the time you are reading this so make sure and check this page for potential updates.
Running the following command from a command prompt will install the RC version of the templates.
dotnet new --install Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-rc1-final
Project Creation
Create a directory for the project and navigate to it in a command prompt. Run the following command to create the new Angular project.
dotnet new angular
Next, if you have a solution you want to add the new project to that can be done with the following command adjusting for the naming of your project and solution.
dotnet sln "ASP.NET Core Basics.sln" add src\AngularWithCli\AngularWithCli.csproj
Installation of Angular CLI
From the command prompt run the following command to install the Angular CLI globally.
npm install -g @angular/cli
After the above, I got the following error trying to run any Angular CLI commands.
You seem to not be depending on “@angular/core”. This is an error.
The problem ended up being that I had not installed all the packages for the project. The issue was cleared up by the following command.
npm install
Angular CLI Usage
Navigate to the ClientApp directory and you can then use all the Angular CLI commands as you would in a stand along Angular application. Some of which can be found here. If you are looking for a quick command to verify all is work the following command works well by running a linter on your project.
ng lint
Wrapping Up
Having templates that are compatible with the Angular and React CLI is a big step forward. The CLIs provide a lot of functionality and by having a setup that doesn’t restrict their usages is a great move. Make note that server-side rendering is no longer enabled by default, but can still be enabled for Angular projects, but not React based projects.
I recommend you check out the official documentation which can be found here.
I hope we see these functionality moves to the other templates that are outside of the templates in this package in order to support Aurelia and Vue.
Also published on Medium.