0% found this document useful (0 votes)
8 views

Part - 2 ASP - NET Core Project File

The document discusses the ASP.NET Core project file. It describes how the project file has changed in ASP.NET Core compared to previous versions. It provides steps to create a new ASP.NET Core project and explains elements of the project file like the target framework, nullable context, implicit usings, and how NuGet packages are referenced.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Part - 2 ASP - NET Core Project File

The document discusses the ASP.NET Core project file. It describes how the project file has changed in ASP.NET Core compared to previous versions. It provides steps to create a new ASP.NET Core project and explains elements of the project file like the target framework, nullable context, implicit usings, and how NuGet packages are referenced.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASP.

NET Core Project File


If you have worked with the previous versions of ASP.NET Framework, then you may know that while
creating a Project in Visual Studio, it creates a project file for us. If you are using C# as the programming
language then it will create the project file with the “.csproj” extension. Similarly, if you are using VB as
the programming language, then it will create the project file with the “.vbproj” extension. But with
ASP.NET Core (.NET), the format and content of the project file have been changed significantly.

Let us understand what changes are made to the ASP.NET Core Project file with an example. So, let’s
create a new ASP.NET Core Empty Project.

Creating a new ASP.NET Core Empty Project:


To create a new ASP.NET Core Application using .NET 6, open Visual Studio 2022, and then click on
the Create a new project box as shown in the below image.

Once you click on the Create a new project box, it will open the “Create a new project” window. This
window includes different .NET 6 application templates. Here we will create a simple Web application
from scratch, so select the ASP.NET Core Empty Project template and then click on the Next button
as shown in the below image.

Once you click on the Next button, it will open the following Configure Your New Project window.
Here, you need to provide the necessary information to create a new project. First, give an appropriate
name for your project (FirstCoreWebApplication), set the location where you want to create this

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


project, and the solution name for the ASP.NET Core Web application. And finally, click on
the Next button as shown in the image below.

Once you click on the Next button, it will open the Additional Information window. Here, you need to
select .NET 6.0 as the Framework, you also need to check the Configure for HTTPS and Do not use
top-level statements check boxes and finally click on the Create button as shown in the below image.

Once you click on the Create button, it will create a new ASP.NET Core Web Application in Visual Studio
2022 using .NET 6 with the following file and folder structure.

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
below steps
1. First, we need to unload the project
2. Then we need to edit the project file
3. Once we edit the project file then we need to save the project file
4. Then reload the project.
But with ASP.NET Core (.NET), we can edit the project file without unloading the project.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


How we can Edit the ASP.NET Core Project File:
ASP.NET Core 1.0 does not create a .csproj file, instead, it uses .xproj and project.json files to manage
the project. This has changed in ASP.NET Core 2.0. Visual Studio now uses the .csproj file to manage
projects. To edit the ASP.NET Core project file, right-click on the project name in the Solution Explorer,
and then select “Edit Project File” from the context menu as shown in the below image.

Once you click on the “Edit Project File” then the Project file will open in the Visual Studio editor as
shown in the below image.

Understanding the ASP.NET Core Project File:


Let us understand the ASP.NET Core Project File elements.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


1. 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 it is
using something called Target Framework Moniker (TFM). In our example, the application
targets the framework net6.0. The net6.0 is the Moniker for .NET 6. If you remember, we created
this project with .NET 6.
2. Nullable: The nullable annotation context and nullable warning context can be set for a
project using the <Nullable> element in your .csproj file. This element configures how the
compiler interprets the nullability of types and what warnings are emitted. The value for this
element is “enable” and “disable”.
3. ImplicitUsings: Implicit usings is a feature in .NET that allows you to have the compiler
automatically add global usings to your projects for common namespaces used in projects of
the type you’ve chosen. This can help you get started more quickly in .NET by automatically
importing common namespaces like System and System.Linq without you having to explicitly
declare them somewhere in your projects. The value for this element is “enable” and “disable”.

Adding Packages in ASP.NET Core:


As we already discussed ASP.NET Core Framework follows Modular approaches. It means by default
it will not include anything i.e. package references to the project. Only the necessary packages which
are required are added by default.

Whenever we add any new packages to our application, then that package reference is also going to
be added to the application project file. Please have a look at the following Dependencies section of
your project. Whenever we add any packages, then that package and its dependency packages are
going to be stored here.

Let us first add a package from the NuGet Package Manager and see what happens. Go to tools =>
NuGet Package Manager => Manage NuGet Packages for Solution… option from the context menu
as shown in the below image.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


Now let us add the Newtonsoft.json package. So, select the browse tab and then search Newtonsoft
and install it as shown in the below image.

Once the package is installed successfully, then you will see, it will add the reference inside the
dependencies section as shown in the below image.

As we have only added one package i.e. Newtonsoft.json, it added that package references here. Along
with the same, it will also add that package reference in the application project file as shown in the
below image.

Note: Once you delete that package, then it will delete the reference from both the dependencies as
well as from the project file.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


Deleting Package in ASP.NET Core:
Again, go to the NuGet Package Manager and select the installed tab and select the package and
uninstall it as shown in the below image.

Once you delete the package, then it should remove the reference from both the dependencies as well
as from the project file. 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.

Note: The CSPRJ file includes settings related to targeted .NET Core Framework, Nullable,
ImplicitUsings, NuGet Package References, etc…

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/

You might also like