Generate ASP.NET Core Application using Yeoman

facebooktwittergoogle_plusredditpinterestlinkedinmail

ASP.NET Core application using Yeoman- Feature
In the previous articles we have seen some brand new features in ASP.NET Core. ASP.NET core is the open source , cross platform and lightweight framework to build web application . It can be built and run on Windows , Mac and Linux. In this article I will explain how to generate ASP.NET Core application using Yeoman generator.

What is Yeoman ?

Yeoman is a command line based scaffolding tool to generate modern applications. It is a cross platform javascript tool on Node.js . Generators are also available for Angular, Backbone and over 1500 + other projects. Any generators in Yeoman have two components , Project generator and sub generator. ASP.NET project generators listed below.

  • Empty Aplication
  • Console Application
  • Web Application
  • Web Application Basic
  • Web API Application
  • Unit test project
  • Class Library
  • Nancy Web Template
  • Sub generators are used to generate new items like views, controllers into ASP.NET project.

    Install NPM , Yeoman and ASP.NET core generator

    NPM (Node Package Manager) is used to install Yeoman . You can download this from npmjs.com for any platform. I got the windows version from Nodejs.org . After installing NPM, go to command line and enter the following command to install Yeoman.

     npm install yo -g

    After this , install the ASP.NET core generator using the following commands .

     npm install generator-aspnet -g

    ASP.NET Core application using Yeoman -Install

    Create ASP.NET Core Application using Yeoman generator

    Type command yo aspnet after installing NPM , Yeoman and ASP.NET generator . This will ask for the type of the application which you want to create .

    ASP.NET Core application using Yeoman -Select Project Type

    ASP.NET Core application using Yeoman - ASP.NET application name

    Select Web Application to generate ASP.NET core application and enter the name . This will create a brand new ASP.NET core project for you. After this you need to perform 3 operations. Rest the DNU ( recommended for first time ) , build the application ( optional ) and run the application using following commands.

    dnu restore 
    dnu build
    dnx web
     
    eg: C:\Users\Tom\yotestprj>dnx web

    Run the ASP.NET core application

    In the command line you will get the URL for our newly created web application. Copy and past it in a browser, then you can see the new ASP.NET core application.

    ASP.NET Core application using Yeoman- ASP.NET core application running

    Create sub generator for the ASP.NET Core

    In the previous section we have created the web application with a template which is similar to the template from Visual studio. As I mentioned earlier , sub generators are used to create new items in the exiting application like ‘add new controller’ . Execute the following command to create a controller .

    yo aspnet:MvcController MyYoController 
    The following two tabs change content below.

    Tom Mohan

    Tom Mohan is a technologist who loves to code and build. He enjoys working on Microsoft Technologies. Tom specializes in ASP.NET MVC, Web API , Azure, C# ,WPF, SQL etc and holds a Bachelor engineering degree in Computer Science. Certification : MCSD , MCTS