This demo demonstrates how to create a simple ASP.NET Core project using Visual Studio 2015.
ASP.NET Core is an open source web framework for building modern web applications that can be developed and run on Windows, Linux and Mac. It includes the MVC 6 framework, which now combines the features of MVC and Web API into a single web programming framework.
In this demo, you will see how to:
-
Create and run a simple website using ASP.NET Core.
-
Take advantage of Visual Studio's support for NPM and Bower.
Follow these steps to set up your environment for the demo.
- Install Visual Studio 2015.
- Open Visual Studio 2015.
Note: Inside the source code you will find an End folder containing a Visual Studio solution with the code that results from completing the steps in the demo. You can use this solution as guidance if you need additional help as you work through this demo.
This demo is composed of the following segments:
-
Go to File | New | Project.
-
In the Templates | Visual C# | Web tab, select the ASP.NET Web Application project. Name it MyWebApplication.
Creating a new ASP.NET Web Application
-
From the ASP.NET 5 Templates list, select the Web Application template.
Selecting the ASP.NET 5 Web Application template
-
In the Solution Explorer, show the dependencies in the project.json file.
Speaking Point: In ASP.NET Core, Visual Studio uses the project.json file for reference and package dependencies, version definitions, framework configurations, compile options, build events, package creation metadata, and run commands, as well as other details. The advantage of this is that the project can be edited and run in Linux and Mac machines that do not have Visual Studio.
Showing the project.json file
-
Show the package.json and bower.json files.
Speaking Point: Both NPM and Bower are now integrated in Visual Studio, as well as the Grunt and Gulp task runners. The Solution Explorer for ASP.NET Core Web Applications has a Dependencies node showing Bower and NPM dependencies. The Bower dependencies are from bower.json in the project folder. The NPM dependencies are from package.json in the project folder.
Showing integrated NPM and Bower
-
In the Dependencies node, note that it is possible to uninstall or update a package through the context menu. This will automatically remove or update the package from the corresponding JSON file.
Showing the Dependencies context menu
-
Click Manage Bower Packages... in the Bower dependencies context menu in order to show the Bower Package Manager UI.
Showing the Bower package manager UI
-
Show the ConfigureServices method in the Startup.cs class.
Speaking Point: ASP.NET Core supports Dependency Injection natively, and as such this method is adding services to the DI container.
Showing the ConfigureServices method
-
Show the Configure method in Startup.cs class.
Speaking Point: ASP.NET Core assumes that no frameworks are being used unless you explicitly tell it that they are, and that is why the Configure method exists. You use this method to tell ASP.NET what frameworks you would like to use for this app. This enables you to have full control over the HTTP pipeline.
Showing the Configure method
-
Show the HomeController.cs file in the Controllers folder.
Speaking Point: ASP.NET Core supports regular controllers (inheriting from the Controller base type) and POCO controllers.
Showing the HomeController
-
Show the Home view Index.cshtml in the Views\Home folder.
Showing the Home view
-
Press F5 to build and run the solution.
Running the web site
By completing this demo, you have walked through Visual Studio 2015 and ASP.NET Core. You have seen the overall structure of the solution and the use of the project.json, bower.json and package.json files to manage the project dependencies. You have also seen how ASP.NET Core added support for native dependency injection.