In this article I will discuss the project and folder structure for the ASP.NET core web application, I have created my first application using ASP.NET core framework in my previous article. This article includes the concepts and role of the wwwroot folder present in the application. I will also discuss about the appsettings.json, global.json and project.json files.
The solution structure for the project is shown in the right hand side of the below figure.
This is the file which contains the information about the project solutions. It contains the information about the location of the folder to check for solution and test projects. The contents of the global.json file as below
"projects": [ "src", "test" ],
The above code shown the version of the .NET core which I have used to create the project. It also contains two folders “src” and “test” which the .NET core will look for the solution and test project respectively.
If nothing is present in these folders, nothing will be compiled and my code will not be available to build.
Startup.cs is the file which .NET core will look for configuration. There is no more global.ascx file present in the project.
What is wwwroot folder?
This is the new root folder. This folder is analogous to the root folder of the classic asp.net. In ASP.NET MVC what ever files we need to exclude from serving to client we need to exclude from routing.
But the same is not true with asp.net core. What ever we want to serve the files by the server to the client we can include it in the wwwroot folder.
The file system will detect the folder structure of the project. One thing we can notice is that there is no .csproj file present for the project which is used to contain the manifest of the project. The file system is the project system in .NET core. ASP.NET core will compile and build my application when a new file is added or removed from the system.
Currently the application is returning the response from the Startup.cs file as shown in the following code.
app.Run(async (context) =>
await context.Response.WriteAsync("Hello World!");
We are getting the result as “Hello World” in the browser.
Now if we simply change the text to “Hello Vikram to new world!” and save the file. We will get the new string even without compiling the project. Follow the following steps to see the change.
Step 1: Run the project (CTRL + F5). The output opens in browser
Step 2: Change the Startup.cs file with new string “Hello Vikram to new world!” and save the file.
Step 3: Refresh the browser opened in step 1. We can see the new string in the browser.
Adding New Files to the project
As I have discussed in the previous section that file system is the project system of the .NET core applications. Lets see this in working.
Step 1: Open the folder containing the project in windows explorer.
Step 2: Add a new file to the opened location as shown in the figure below.
Step 3: Once the file is added in the file system we can see the same file is added in the solution explorer in the Visual Studio as shown in the figure below.
Since there is no need to add the new files using the project. ASP.NET core will compile and build my application when a new file is added or removed from the file system from the project.
This justifies the absence of .csproj file for the .NET core application. .csproj file used to contain the references and dependencies.
In asp.net core the solution explorer reflects whats on the disk one to one that is why there is no need of the .csproj file which include the project files. As we can add files in the project by adding the files in the folder.This will save lots of time in resolving file conflicts while working on the source control.
The dependencies are managed by nuget package manager in .NET core applications.
All top level dependencies and libraries that are used by the application are listed in project.json.
In the article I have discussed about the project and folder structure of the asp.net core web applications. I have also discussed the importance of the file system in building and compiling the project.