In this article, I am going to discuss the ASP.NET Core Project File in detail. Please read our previous article before proceeding to this article, where we discussed how to create ASP.NET Core Web Application as well as we also discussed the different project templates that are available as part of ASP.NET Core Web Application.
If you worked with the previous versions of ASP.NET Framework, then you may know, if you are using C# as the programming language then the framework will create the project file with ”.csproj” as the extension. Similarly, if you are using VB as the programming language, then it will create the project file with “.vbproj” as the file extension. But with ASP.NET Core, the format and content of the project file have been changed significantly.
Changes in the Project file in ASP.NET Core Application:
The ASP.NET Core Project File does not contain any references for folder or file. In previous versions of ASP.NET Framework, when we add a folder or a file to the project using Solution Explorer, then a reference to that folder or file is added in the project file. But with ASP.NET Core, the Project File does not include any reference for the Files or Folders added the project using Solution Explorer.
Another significant change in ASP.NET Core is, the File System determines what folders and files belong to the project. Generally, the files and folders which are present at the project root folder are part of the project. Those files and folders which are present at the project root folder are only going to display in the Solution Explorer.
So, if you add a file or a folder using the File Explorer, then that file or folder is part of the project. As soon as you add a file or folder using the file explorer, it immediately displayed in the solution explorer. In the same way, if you delete a file or folder from the Project Folder or any of its subfolders, then that deleted file or folder is no longer part of the project and that is reflected immediately in the Solution Explorer.
How we can Edit the Project File in Previous Versions of ASP.NET:
In our previous versions of ASP.NET Framework, in order to edit the project file, we need to follow the following steps
How we can Edit the ASP.NET Core Project File:
To edit the ASP.NET Core project file, right-click on the project name in the Solution Explorer, and then select “Edit FirstCoreWebApplication.csproj” as shown in the below image.
Once you click on the “Edit FirstCoreWebApplication.csproj” then the file will open in the editor as shown below.
Understanding the ASP.NET Core Project File:
Let us understand the ASP.NET Core Project File elements.
TargetFramework:
The TargetFramework element in the project file is used to specify the target framework for your application. To specify the target framework in the project file we are using something called Target Framework Moniker (TFM).
In our example, the application targets the framework netcoreapp2.2. The netcoreapp2.2 is the Moniker for .NET Core 2.2. If you remember, while we are creating this project, we select .NET Core 2.2 as the target framework.
AspNetCoreHostingModel:
The AspNetCoreHostingModel element of the project file is used to specify how we are going to host the asp.net core application. Values for this AspNetCoreHostingModel element are either InProcess or OutOfProcess.
The value InProcess specifies that we are going to use the in-process hosting model for our application. It means we are going to host the ASP.NET Core Application inside of the IIS Worker Process which is nothing but w3wp.exe.
The value OutOfProcess specifies that we are going to use the out-of-process hosting model. In a later article, we will discuss the In Process and Out Of Process hosting model in detail.
PackageReference:
The Package Reference element of the project file is used to add the references to all the NuGet packages which are installed for your application. At the moment, the project file adds references for the following 2 NuGet packages.
Microsoft.AspNetCore.App:
Microsoft.AspNetCore.App NuGet package is generally called the Meta Package. The Meta Package has not any content of its own but it contains a list of dependencies i.e. it contains other packages.
You can find this Meta Package, in the Solution Explorer, under NuGet which is present inside the Dependencies. When you expand the Meta Package, then you will find all the dependencies as shown in the below image.
As you can see in the project file, there is no version number for the Meta Package. When the version for a package is not specified, then an implicit version is specified by the SDK. In our upcoming articles, we will discuss more regarding Meta Package and implicit version.
Microsoft.AspNetCore.Razor.Design:
Microsoft.AspNetCore.Razor.Design package contains MSBuild support for Razor. This is also referenced by Microsoft.AspNetCore.App Meta Package.
In the next article, I am going to discuss the Main method in the ASP.NET Core application. Here, in this article, I try to explain the ASP.NET Core Project File in detail. I hope you enjoy this article and I would like to have your feedback. Please post your feedback, question, or comments about this article.
Summary:
I hope this post will be helpful to understand the ASP.NET Core Project File
Please share this post with your friends and colleagues.
For any queries please post a comment below.
Happy Coding 😉
If you worked with the previous versions of ASP.NET Framework, then you may know, if you are using C# as the programming language then the framework will create the project file with ”.csproj” as the extension. Similarly, if you are using VB as the programming language, then it will create the project file with “.vbproj” as the file extension. But with ASP.NET Core, the format and content of the project file have been changed significantly.
Changes in the Project file in ASP.NET Core Application:
The ASP.NET Core Project File does not contain any references for folder or file. In previous versions of ASP.NET Framework, when we add a folder or a file to the project using Solution Explorer, then a reference to that folder or file is added in the project file. But with ASP.NET Core, the Project File does not include any reference for the Files or Folders added the project using Solution Explorer.
Another significant change in ASP.NET Core is, the File System determines what folders and files belong to the project. Generally, the files and folders which are present at the project root folder are part of the project. Those files and folders which are present at the project root folder are only going to display in the Solution Explorer.
So, if you add a file or a folder using the File Explorer, then that file or folder is part of the project. As soon as you add a file or folder using the file explorer, it immediately displayed in the solution explorer. In the same way, if you delete a file or folder from the Project Folder or any of its subfolders, then that deleted file or folder is no longer part of the project and that is reflected immediately in the Solution Explorer.
How we can Edit the Project File in Previous Versions of ASP.NET:
In our previous versions of ASP.NET Framework, in order to edit the project file, we need to follow the following steps
- First, we need to unload the project
- Then we need to edit the project file
- Once we edit the file then we need to save the project file
- Then reload the project.
How we can Edit the ASP.NET Core Project File:
To edit the ASP.NET Core project file, right-click on the project name in the Solution Explorer, and then select “Edit FirstCoreWebApplication.csproj” as shown in the below image.
Once you click on the “Edit FirstCoreWebApplication.csproj” then the file will open in the editor as shown below.
Understanding the ASP.NET Core Project File:
Let us understand the ASP.NET Core Project File elements.
TargetFramework:
The TargetFramework element in the project file is used to specify the target framework for your application. To specify the target framework in the project file we are using something called Target Framework Moniker (TFM).
In our example, the application targets the framework netcoreapp2.2. The netcoreapp2.2 is the Moniker for .NET Core 2.2. If you remember, while we are creating this project, we select .NET Core 2.2 as the target framework.
AspNetCoreHostingModel:
The AspNetCoreHostingModel element of the project file is used to specify how we are going to host the asp.net core application. Values for this AspNetCoreHostingModel element are either InProcess or OutOfProcess.
The value InProcess specifies that we are going to use the in-process hosting model for our application. It means we are going to host the ASP.NET Core Application inside of the IIS Worker Process which is nothing but w3wp.exe.
The value OutOfProcess specifies that we are going to use the out-of-process hosting model. In a later article, we will discuss the In Process and Out Of Process hosting model in detail.
PackageReference:
The Package Reference element of the project file is used to add the references to all the NuGet packages which are installed for your application. At the moment, the project file adds references for the following 2 NuGet packages.
- Microsoft.AspNetCore.App
- Microsoft.AspNetCore.Razor.Design
Microsoft.AspNetCore.App:
Microsoft.AspNetCore.App NuGet package is generally called the Meta Package. The Meta Package has not any content of its own but it contains a list of dependencies i.e. it contains other packages.
You can find this Meta Package, in the Solution Explorer, under NuGet which is present inside the Dependencies. When you expand the Meta Package, then you will find all the dependencies as shown in the below image.
As you can see in the project file, there is no version number for the Meta Package. When the version for a package is not specified, then an implicit version is specified by the SDK. In our upcoming articles, we will discuss more regarding Meta Package and implicit version.
Microsoft.AspNetCore.Razor.Design:
Microsoft.AspNetCore.Razor.Design package contains MSBuild support for Razor. This is also referenced by Microsoft.AspNetCore.App Meta Package.
In the next article, I am going to discuss the Main method in the ASP.NET Core application. Here, in this article, I try to explain the ASP.NET Core Project File in detail. I hope you enjoy this article and I would like to have your feedback. Please post your feedback, question, or comments about this article.
Summary:
I hope this post will be helpful to understand the ASP.NET Core Project File
Please share this post with your friends and colleagues.
For any queries please post a comment below.
Happy Coding 😉
0 comments:
Post a Comment
If you like this website, please share with your friends on Facebook, Twitter, LinkedIn.