Advertisement
Intermediate .NET, .NET CLI, SDK & Project Structure (csproj)

How do you add, remove, and list NuGet package references using the dotnet CLI?

Short answer

`dotnet add package ` adds a PackageReference to the .csproj (optionally with --version), `dotnet remove package ` removes it, and `dotnet list package` shows all references, including outdated or vulnerable packages with the --outdated or --vulnerable flags.

Save .NET mock interview
Advertisement
AModel answer
`dotnet add package <PackageId>` adds a PackageReference to the .csproj (optionally with --version), `dotnet remove package <PackageId>` removes it, and `dotnet list package` shows all references, including outdated or vulnerable packages with the --outdated or --vulnerable flags.
dotnet add package Serilog.AspNetCore --version 8.0.0
dotnet list package --outdated
dotnet remove package Newtonsoft.Json
Real-world example
A security audit runs `dotnet list package --vulnerable` across every project in a solution as part of a scheduled CI job to catch known CVEs in third-party dependencies before they reach production.
Likely follow-ups
  • How does --outdated differ from --vulnerable in its data source?
  • How do you restore packages from a private NuGet feed?
Related topics