ASP.NET Project File

March 5, 2021   • aspnet-core programming

The project file is one of the most important files in an ASP.NET Core application. It tells .NET how to build the project. All .NET projects list their dependencies in the .csproj file. If you have worked with JavaScript before, think of it like a package.json file. The difference is, instead of a JSON, this is an XML file.

When you run dotnet restore, it uses the .csproj file to figure out which NuGet packages to download and copy to the project folder. NuGet is a package manager for the .NET ecosystem. Microsoft developed it to provide access to thousands of packages written by .NET developers. You can also use it to share the code you wrote with others.

The .csproj file also contains all the information that .NET tooling needs to build the project. It includes the type of project you are building (console, web, desktop, etc.), the platform this project targets, and any dependencies on other projects or 3rd party libraries.

Here is an example of a .csproj file that lists the Nuget packages and their specific versions.

<Project Sdk="Microsoft.NET.Sdk.Web">
		<PackageReference Include="AWSSDK.S3" Version="" />
		<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.1" />
		<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
		<PackageReference Include="Npgsql" Version="" />
		<PackageReference Include="Serilog" Version="2.10.0" />

In this example,

  • The SDK attribute specifies the type of .NET project.
  • TargetFramework is the framework this application will run on, .NET 5 in this case.
  • The PackageReference element includes the NuGet packages. The Version attribute specifies a version of the package we want.