liveBook · Manning

Package

As explained in Pro ASP.NET Core 7, Tenth Edition

A software package is a distributable unit containing reusable code, resources, and metadata for incorporation into a project.

A package adds a feature that an ASP.NET Core project does not already have. Database access, command-line tools, and browser-facing CSS are different needs, so they use different package-management commands. Installing a package is only the first step: the project must also use what it provides. section 4.4 section 4.0

Choose the command by what the package supplies:

  • For a .NET project dependency, run `dotnet add package` in the folder containing the `.csproj` file. The resulting `PackageReference` records its name and version in the project file; direct XML editing usually is not needed. section 12.3.2
  • For a command-line tool, use `dotnet tool install --global`. For example, `dotnet-ef` supplies commands used to prepare and create Entity Framework Core databases; it is installed separately from the project's Entity Framework Core packages. section 7.2.1
  • For files delivered to a browser, use LibMan. It can fetch CSS, JavaScript, images, and HTML from a configured provider into a project directory, conventionally `wwwroot/lib`. Reference installed CSS or JavaScript from the page. section 4.4.3 section 15.4.2

Add a .NET dependency

From the project folder, run `dotnet add package Swashbuckle.AspNetCore --version 6.4.0`. Check the `.csproj` file for a `PackageReference` with that name and version. Entity Framework Core and its SQL Server support are likewise added with `dotnet add package`; Identity support for Entity Framework Core requires another package. section 12.3.2 section 7.2.1 section 11.1.1

Add browser-facing styles

Install LibMan, run `libman init -p cdnjs` in the project folder, then run `libman install bootstrap@5.2.3 -d wwwroot/lib/bootstrap`. Add a stylesheet link to `/lib/bootstrap/css/bootstrap.min.css` in an HTML page and apply Bootstrap classes to an element. Request the page to check the result. LibMan records its provider and libraries in `libman.json`; `unpkg` is another provider option. section 4.4.3 section 15.4.2

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Works through installation commands, dependency records, LibMan configuration, and HTML usage, without detailing how packages are built.
Examples
Uses Swashbuckle.AspNetCore and Entity Framework Core dependencies, a global `dotnet-ef` tool, and Bootstrap installed through LibMan.
What it assumes
Assumes an ASP.NET Core project and command prompt, while showing the commands and configuration needed to add packages.
What you can do after
Operate/configure package management with `dotnet add package`, `dotnet tool`, and LibMan, then reference installed browser assets in HTML.
How it connects
Connects packages to project files, MSBuild, Entity Framework Core, static content, and HTML stylesheet links.

Also explained in

Compare how 8 books explain package →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.