ASP.NET Core MVC 2.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

In this recipe, we will do the following:

  1. Install Homebrew by entering this command at a Terminal:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
  1. Use Homebrew to get DNVM, DNX, and DNU using the commands as follows:
$ brew tap aspnet/dnx 

$ brew update 

$ brew install dnvm 

$ source dnvm.sh 
  1. Install Node.js and npm (the npm will be installed automatically with Node.js):
$ brew install node
  1. Verify Node.js and NPM versions:
$ node -v 

$ npm -v 

The version currently being used will be displayed on your screen as follows:

  1. Install Yeoman with Gulp to help automate tasks:
$ npm install -g yo gulp 

$ npm install -g generator-aspnet 
  1. Yeoman asks us what type of application we want to create. In our case, we choose Web Application Basic.
  2. After that, Yeoman asks us the name for the application to create, as shown in the following screenshot.
  3. Yeoman will generate all the necessary files to run an ASP.NET Core MVC application. After the project is created, Yeoman shows us the different commands we can use to run the application.
  4. With the command cd "nameoftheapplication", we are placed in the application directory.
  1. After that, we can run the dotnet restore command, which will restore all the dependencies needed to run the application. In the background, this command will connect to the NuGet online repository to download, as NuGet packages the missing dependencies:
  1. Build and run webapp1 typing the following command:
$ dotnet run

After executing the preceding command you get the following output at localhost:5000: