One of the great things about ASP.NET 5 its openness and support for cross-platform development. This post is going to walk through using Yeoman to create a new ASP.NET 5 application and then run that application from the command line. This will give you the same application as Visual Studio just without the Visual Studio solution.
First make sure node.js is installed. The installer can be found here. Node comes with a package manager called npm automatically. Don’t know anything about npm? Watch this introductory video.
Yeoman is a scaffolding tool that uses templates called generators. First using the following command from the command prompt to install Yeoman. As a note all the commands in this post should be run from the command prompt.
npm install -g yo
Next install the generator for ASP.NET 5 which is provided by the OmniSharp team.
npm install -g generator-aspnet
Now tell Yeoman to run the ASP.NET 5 generator.
yo aspnet
Below is a screenshot of the results. This is where the type of application to be generated is chosen. In this case I am choosing a Web Application.
Next enter the name of the application. In this case WebApp1.
After the creation process is done a set of commands are show as the next steps.
This command changes to the directory created during the generation process.
cd "WebApp1"
DNX Utility or dnu is a tool used to manage operations related to packages an application uses. The restore command finds all the dependencies of your application and downloads them. Not only does restore get the top level of dependencies but it also gets all the sub dependencies.
dnu restore
DNUÂ build runs the build process to produce the assemblies for an application.
dnu build
DNX is a .NET execution environment. It contains all that is needed to run an application. The run command is for console applications as the output from the generator said and does not apply to a web application.
Kestrel is a development web server that works cross platform. The web command uses this project and only works on Windows I believe.
dnx . web OR dnx . kestrel
At this point a web server is running and should the application will be viewable in a browser on a local host address. The exact url can be found in the hosting.ini file of the project.
The list of commands defined for an application can be found in the project.json file command section. The command section defines named entry points for the application. The following is the commands section of WebApp1 which defines both kestrel and web.
"commands": { "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --config hosting.ini", "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --config hosting.ini" }