Everything you need to know about ASP.NET 5 Project Template

Its been a quite while that ASP.NET 5 is out there. Idea of this post is to help migrate to the new project template that comes with Visual Studio 2015. Lets get started.

OK, first things first.. lets get started with a new project. In the Visual Studio 2015 just >

New Project Template Dialog

In this dialog box make sure you have select ASP.NET Web Application and fill in the details.

Name : MyFirstASPNET5
Location: Where your project files gonna store
Solution name: MyFirstASPNET5

And click OK.

In the New ASP.NET Project dialog box select Web Application under ASP.NET 5 Preview Templates option. (NOTE: ASP.NET 5 is still on its preview stage.).

New Project Dialog

For the moment we are not going to create any test projects for this tutorial. After selecting Web Application under ASP.NET 5 Preview Templates click OK button. Visual Studio might ask you to create a Azure Website using this project template. If you do not wish to create a Azure Website just click Cancel in the next dialog box. Now wait for few seconds till Visual Studio create the base template for you. This base template is a starting point for your ASP.NET 5 Web Application. And its a fully working start point for you. By just pressing you can go through this base template.

This is how it looks like
Base Template

Press for a quick preview of this template up and running. (ASP.NET5 running on Microsoft Edge)
ASP.NET 5 on Edge

OK, so far everything is working fine and lets close the browser and go through the Solution Explorer. By default you should see the Solution Explorer is in the right hand side of your Visual Studio 2015 window. If not click View > Solution Explorer or just press CTRL + ALT + L 

View Solution Explorer

The Solution Explorer

The Solution ExplorerASP.NET project template will look like this. It might not change a much when the full release is available. As you remember a total new way of keeping the configurations and the folder structures.

You have a Solution Items folder that holds the global configurations for the solution. Yep you are correct its a JSON file. Also you get these References for your project as usual. And a whole new wwwroot section to hold the static files. Again as usual Controllers, Models and Views. And a Dependencies for your project dependencies.

And code first Migrations are enabled by default and it got is on folder in the root level. And all other JSON configuration files.

Finally a whole new folder for the Services you use, such as sending emails from you web application.

global.json

This file contains mainly two parts. The detail of the project and the sdk used by the whole solution.

Source FolderThe projects property has values to tell where your source code is stored. By default it stores under a folder named src . All your source is stored under this folder. Yes you can change this name without any problems. This will help all the build artifacts to store in the different folder named artifcats  and can be easily omit from the source controlling. Can keep your code much more organised by default. Cool isn’t it.

And sdk will store the version of the DNX (.Net Execution Environment) which Visual Studio will use it when you load the solution. Yes you can store different SDK values in the project.json file for different projects that use different versions of SDKs in the same solution.

wwwroot section

wwwroot SectionThis sections stores all your content files. As you see it has css, images, all your javascript files and the different libraries you use to make your development much more easier.

In the previous versions of ASP.NET the web root was the project root of the solution. It allowed to access all the static files as well as the configuration files such as web.config and global.asax. For protecting these configuration files you had to write specifically to protect these files. Also known as blacklisting.

But creating a separate section for all these static files in this new template and make it your root of the site. You do not need any extra effort for protecting. wwwroot just contains all the static files and other content that needs to start off your website.

Apart from the security this separation will simplify the minification and bundling of your static files such as css and javascript files.

Dependencies

Client side dependencies The Dependencies section will hold all he client side stuff that your project will depend on. It has two folders, Bower and NPM. These folders hold two package managers (like NuGet) with corresponding names. These two will pull all the dependencies as per seen in the image.

The bower dependencies are controlled by the bower.json file.

As you see each dependency can be controlled separately within this file. Also indicating how it should be deployed to the wwwroot folder when the bower task is executed.

NOTE: All the server side dependencies are controlled under References section. 

config.json

ASP.NET 5 no longer stores its application wide configuration settings using XML. Previously this file is known as web.config. All these settings are stored under config.json using JSON format. By default the file should look like this (at final release the content might change).

Again there is nothing fancy or you must have this file for your configurations. Not like ever growing web.config file you can have separate configuration files in a project. This main file by default accessed using Startup.cs in your root folder.

As you can see in the Startup method the builder variable collects all the configuration files you have in your project. So you can keep all your configurations in separate files for easy access and for maintainability and for the readability.

Summary

ASP.NET 5 introduces a few concepts that didn’t exist in previous versions of ASP.NET. Rather than working with web.config, packages.config, and a variety of project properties stored in the .csproj/.vbproj file. And developers can work these separate folders and files for maintainability and for security. Yes there will be a learning curve and its worth it !!!