Tuesday, November 22, 2016

.NET Core: Create web application with Yeoman template generator

1 Introduction


This article describes how to create ASP.NET Core web application using Yeoman template generator. When we create a ASP.NET Core application in windows platform, we can use visual studio templates. since ASP.NET Core is supported in Linux and Mac like platforms, we can use template generator tool like Yeoman to create a basic project template.


2 What is Yeoman?


Yeoman is a free open source tool. It’s more like visual studio project templates. It’s going to create a complete project with given set of tools. Yeoman has set of generators, It complies with industry best practices. Developers can easily start with their applications with specific tool set, without worrying about the setup or template of the application. Yeoman templates includes building, testing and minification in your application, So developer can focus on the logic of their application.


3 Install node js















 sudo apt-get install nodejs
 node --version


Install node js, before installing Yeoman. Yeoman is going to run on a node server, After installing node js check the version of it.


4 Install npm






















 sudo apt install npm


When we install nodejs, npm is also comes along with it. If you start installing npm before installing node js, follow like this.

npm is a package manager for Yeoman, It’s going to download any dependencies in your application, You don’t want to manually download and install it.


5 Let’s try to install Yeoman!!










 npm install -g yo


Run Yo installer command,




















But it doesn’t seem work, We get an ugly permission issue, Let’s try to fix this.

It says permission denied for some paths. It suggests to run installer command as root/Administrator, Let’s try out that.




























It looks perfectly fine, when we use sudo command with yo installer command.













 yo


We can check whether Yeoman is installed properly using Yo command.

We have successfully installed Yeoman. Now we don’t want to manually create .NETCore applications. We can use generated templates using Yo. Let’s start using Yeoman templates.

create a new directory and cd into it. Then run yo command.












Run Yo command, and check what happens.

It points to Install a generator by default. It doesn’t point to Run a generator, until we install a generator.










search for asp net generator in npm package management store.





















We get a permission issue when installing asp net generator, Let’s try what yo says, will run npm install command and see what happens.







 npm install -g generator


We tried to install generator using npm install command, But it shows the same error!!!!

Since this is a permission issue, will run the command with sudo and check what happens.








 sudo npm install -g generator-aspnet


When installing generator as an administrator, it installs without getting any errors.

Let’s run Yo command and select a template.




























Select aspnet as generator, and then select what type of application you want to create.

Select Empty Web Application and give a name to it.



















Go inside the project folder and open it in visual studio code.

In visual studio code add .vscode folder and restore relevant packages. It shows solution like this.






































In program.cs file, It shows WebHostBuilder class, with cross platform Kestrel server and IIS integration both.

It has defined a separate Startup class, to configure the http request pipeline.












Build and run .NETCore application and check terminal window,

You can see logging is enabled for browser navigation.

We can see complete project is created using Yeoman template generator. It includes program.cs, project.json and web.config files.

It includes Startup class to manage the http request pipeline. And also it has a wwwroot folder to host our web application.

Since Yeoman is generating complete application, We don’t have to do anything manually. We can only focus on the application logic and start working on it.


6 Download

6.1 TechNet Gallery



6.2 GitHub



7 Conclusion


If you go thorough this article, you will understand how easy it is to create a basic .NET Core template using Yeoman


8 References




1 comment: