liveBook · Manning

Project

As explained in ASP.NET Core in Action, 3e

A project is a .NET unit of deployment containing the source files and configuration needed to build an application or library.

A .NET project is a unit of deployment: it contains the source files and configuration needed to build an application or library. It is compiled into an output such as a .dll or executable. A solution can hold multiple projects so they can be developed and built together. section 3.2.1 section 3.5

A template provides a quick starting point by creating a project and configuring fundamental pieces. Visual Studio and the .NET CLI provide templates for web applications, console applications, and class libraries. section 3.2.1

Listing 3.1 Creating a new minimal API application with the .NET CLI
dotnet new sln -n WebApplication1     #1
dotnet new web -o WebApplication1     #2
dotnet sln add WebApplication1        #3

These .NET CLI commands create a solution, create an empty web project, and add the project to the solution. section 3.2.1

An empty ASP.NET Core project has a few important files and folders:

  • The .csproj file describes how to build the project and lists its NuGet package dependencies. section 3.4
  • Program.cs contains the code that configures and starts the application. section 3.4 section 3.8
  • appsettings.json and appsettings.Development.json provide runtime configuration; Properties/launchSettings.json controls how Visual Studio runs and debugs the app. section 3.4
  • In Visual Studio, Dependencies and Connected Services show dependencies and remote services; they are not corresponding folders on disk. section 3.4

The .csproj file specifies the project SDK, target framework, and options such as nullable reference types and implicit using statements. Files are included in the build automatically, and NuGet packages can be referenced directly with PackageReference elements. In Visual Studio, double-click the project name in Solution Explorer to edit the file. section 3.5

Listing 3.2 The .csproj project file, showing SDK, target framework, and references
<Project Sdk="Microsoft.NET.Sdk.Web">               #1
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>       #2
    <Nullable>enable</Nullable>                     #3
    <ImplicitUsings>enable</ImplicitUsings>         #4
  </PropertyGroup>
</Project>

This minimal web project file targets .NET 7 and enables nullable reference types and implicit using statements. section 3.5

Add a database provider

To use EF Core with SQLite, add the SQLite provider and EF Core design packages as PackageReference elements in the .csproj file. Restore the packages with dotnet restore, or let Visual Studio restore them. The provider supplies runtime database support; the design package supplies shared build-time components. section 12.2.1

Project settings depend on the kind of application. A worker service uses Microsoft.NET.Sdk.Worker rather than Microsoft.NET.Sdk.Web and explicitly references Microsoft.Extensions.Hosting. It may also need explicit references for functionality included implicitly by the Web SDK. section 34.2.1

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains template creation, project layout, SDK and framework settings, package references, and differences between web and worker projects.
Examples
Uses an empty minimal API project, an EF Core SQLite setup, and a worker service project file.
What you can do after
Operate and configure a project using Visual Studio or the .NET CLI, including adding and restoring NuGet packages.
How it connects
Connects projects with solutions, NuGet packages, target frameworks, runtime configuration, and Entity Framework Core database providers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.