Share via


Exploring .NET Core | ASP.NET Core 1.0 MVC Project Structure Overview

Let’s discuss structure of ASP.NET Core MVC Web Application Project. We are going to use project created in our last discussion Welcome to ASP.NET Core 1.0 MVC. We have following major areas:

  • Properties
  • References
  • wwwroot
  • Dependencies
  • Controllers
  • Views
  • Program.cs
  • Startup.cs
  • Configuration Files

https://1.bp.blogspot.com/-DJXAGCN0PuQ/V7JoxQJf_zI/AAAAAAAAACU/5YS_BFCtzA80YBRUeTyup7Zok4sWTuk4ACK4B/s640/Project%2BStructure%2BOverview.png

Properties

Properties section contains launchSettings.json file which has project settings. Although it can be edited directly, yet it is generally edited by other interfaces like project properties.

https://1.bp.blogspot.com/-uIQCxH0QBA4/V9Hfe6U--bI/AAAAAAAAALg/UYUjjrOz14sS10ImBAj3eVCv8R1sD2fWgCK4B/s640/Properties.png

References

References section contains all DLL references added to project. Visual Studio 2015 shows added references in groups. For this template, Visual Studio adds .NET Core Application related DLLs.

https://2.bp.blogspot.com/-DxefV1nEXKQ/V9HfnkW0CyI/AAAAAAAAALo/WSniWKOybxcKZdVbfl3OtDOnNq7goWTrACK4B/s640/References.png

We can add new references directly or through NuGet Packages.

  • To add reference from other project of same solution, Open Reference Manger Screen from Context Menu of Project References >> Add References. And then on Reference Manager Screen >> Projects >> Solution >> Select Project Name.
  • To add reference from existing DLLs, Open Reference Manger Screen from Context Menu of Project References >> Add References. And then on Reference Manager Screen >> Assemblies >> Browse >> Select Required Assemblies to be added.
  • To add references from NuGet, Open NuGet Manger Screen from Context Menu of Project References >> Manage NuGet Packages. And then on NuGet Manager Screen >> Browse >> Search and Install Required Assemblies to be added.
  • Open Package Manger Console through Tools >> NuGet Packet Manger >> Package Manger Console and run install command "Install-Package FullPackageName".

wwwroot

wwwroot is a special folder which contains all the static resources like css, images, JavaScript and included libraries. Visual Studio Template uses wwwroot name by default, but we can change it as per requirements.

https://2.bp.blogspot.com/-UBmN4uJMexk/V9HgNpmk-QI/AAAAAAAAAL0/lPd2WBAl4VENpLCOMVXNmXTbz77P2ikEwCK4B/s640/Wwwroot.png

Dependencies

Dependencies section contains list of third part dependencies added to project through Bower. By default this template adds: bootstrap, jquery, jquery-validation and jquery-validation-unobtrusive.

https://1.bp.blogspot.com/-hCp72PACQTM/V9HgX0QSE4I/AAAAAAAAAL8/tFOXsMaownwa1_pRyRH31HSzMKKuB41TwCK4B/s640/Dependencies.png

We can add new bower through Manage Bower Packages.

  • To add new bower Open Manage Bower Packages Screen from Context Menu of Project Bower >> Manage Bower Packages. And then on Manage Bower Packages Screen >> Browse >> Search and Install Required Packages to be added.

Controllers

Controllers folder contains controllers added to application. It is not necessary to add controllers to this folder or to create this folder, but it is one of practices to add controllers to this folder or its subfolders. This templates add HomeController by default with Index, About and Contact action methods.

https://2.bp.blogspot.com/-FduJQ0nKM9s/V9HgclRAmTI/AAAAAAAAAME/ITNVf0y2_fQtGdUU1zhdqsUM2idjUXcRwCK4B/s640/Controllers.png

Views

Views folder contains views in 3 categories:

  • Controller Views
  • Shared Views
  • Special Views

Controller Views

All the views related to a controller have views in a folder named to that controller. This example Home folder contains views for each action method of HomeController.

Shared Views

Shared views folder contains: _Layout and Error view. _Layout view contains layout of application and in term of ASP.NET it replaces Master Page. Error view contains the implementation of error page which is displayed to end user in case of any error.

Special Views

While there are 2 special views in this template: _ViewImports and _ViewStart. _ViewImports contains the list of imports for all views. And ViewStart contains generic page initializations like layout globally.

https://1.bp.blogspot.com/-ahQBi5ea4AA/V7JppiKOICI/AAAAAAAAADY/yquGbWR8PUgpMzIJdZfKOfRuS7Sd64JQQCK4B/s640/Views.png

Program.cs

Program.cs contains Main method, which is starting point of application. It initializes WebHostBuilder instance and starts the host environment. We can set web server related configurations in this area. We will have complete detailed discussion on this item separately.

https://1.bp.blogspot.com/-0Phprg9Irdo/V7JpvkWyVLI/AAAAAAAAADg/pPFlgEr_Z6YHJbaLe38ibY5TIkR8mQKxACK4B/s640/Program.png

Startup.cs

Startup.cs contains main implementation for Environment Startup. This class not only initialize basic environment configurations and request pipeline but also other features like logging, error page and routing. We will have complete detailed discussion on this item separately.

https://4.bp.blogspot.com/-2pQqkyJ5S8Y/V7Jp0F7H-kI/AAAAAAAAADo/joE5MaIgZJoARw9T77ZtZKf7pkofEwEiACK4B/s640/Startup.png

Configuration Files

This template creates different configuration files of .config and .json type at root of project:

  • appsettings.json 
  • bundleconfig.json 
  • project.json
  • web.config

These files contains application settings, configurations related to bundling and minification and project settings. We can also use ini files, environment variables, command line arguments and even custom configuration provider. We will have complete detailed discussion on this item separately.

https://1.bp.blogspot.com/-AmRq-6KDMPY/V7Jp5d-zROI/AAAAAAAAADw/00whRYA6LjMAG0lndMVC6JHAqjSCydDQgCK4B/s640/Configuration%2BFiles.png

See Also

Exploring .NET Core | How to install .NET Core 1.0
Exploring .NET Core | Welcome to ASP.NET Core 1.0 MVC