ASP.NET uses a tool called yeoman to assist in the development of applications for the web by generating the base project file structure and configurations so you can get to work quickly; rather than fiddling around with the same things every time you need to create a new project.
You can install Yeoman using the following command:
Ensure that you used the -g flag to tell the system you want Yeoman available globally.
Next we can install the ASP.NET templates using the following command: (include the -g again for global)
You can now run the ‘yo’ cmdlet to view the current installed generators on your system:
You can see we have Aspnet installed and listed. Run this generator by using the following cmdlet:
At this point we want to generate a Web Application, so you can either use the arrow keys, or simply type 3 which corresponds to the third entry; then hit Enter
You will be asked to specify a name for the project, I’ve just chosen to call it TheWorld
Have a look into the directory you generated the files into and you’ll notice all the standard project files are generated for you.
Using Visual Studio Code (VS Code)
Next we want to open this project in VSCode. This can easily be done by simply typing:
You will be greeted with the lightweight visual studio code suite with the files we just generated loaded into the Working File menu.
Go ahead and open the project.json file (you’ll recognize this file from the previous tutorial) and have a look at its contents.
The first block is some of the simple project specifications relating to version and namespace.
The next block is one we’ll be using quite regularly, the dependencies for the project listing the NuGets we’re going to use when building our application.
Finally we’ve got some specified commands and housekeeping code.
Next open up the Startup.cs file. You’ll notice along the top bar that there will be unresolved dependencies which you’ll be asked to resolve by clicking Restore.
A terminal windows will spring open and begin downloading and installing all the required NuGet packages. If this is your first time using these NuGet packages, there’s a good chance it’ll take some time to install.
You will now get intellisense on most of your project! Yay!.
Just back into the project.json file and have a look at the code between the ‘commands’ braces. You should see two:
So let’s give one of them a go. Open your terminal windows again and run the following:
Near the end of the output you’ll see the following lines that indicate that you have a webserver running on port 5000 hosted on the local machine.
Go ahead and open your web browser to the specified location and you’ll be greeted with a wonderful splash screen that is actually your ASP.NET instance running from the command line. You can view live requests chains in the terminal windows as you navigate around the splash screen.
Summary
We’ve learned how to generate code using Yeoman and edit/view it in Visual Studio Code. In the next lesson we’ll be learning how to do the same thing, from scratch in Visual Studio 2015. Hopefully I’m not going into too much detail, but I think it’s beneficial to have the whole process documented instead of assuming everything will understand exactly what’s going on.