dotnet package and nuget Commands
|
This section documents MSBuild 18.9, the .NET SDK 10.0.402 (with its This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The C# Reference bibliography lists the reference material consulted while preparing these pages. |
The dotnet CLI exposes NuGet through two command families: dotnet package for a project’s package references
and dotnet nuget for everything else — sources, caches, signatures, publishing. This page is the reference for
both with .NET SDK 10.0.402 (NuGet 7.9.0); each command links to the page where it is used in context. push,
delete and sign are covered in the publishing group
(Publishing to nuget.org,
Signing Packages).
dotnet package add
| Option | Effect |
|---|---|
|
The version (default: the latest stable). Note |
|
Allow prerelease versions when no version is given. |
|
Add the reference only for one target framework (a conditioned |
|
Add without the restore preview and compatibility check. |
|
Source for the restore preview. |
|
Global-packages folder for the restore preview. |
|
Allow credential prompts. |
|
The project, or a file-based app (writes a |
Before writing the reference, add restores the project with the new package to check that it is compatible and
resolvable; --no-restore skips that and writes blindly. In a Central Package Management repository it writes the
version to Directory.Packages.props.
Source: dotnet package add.
dotnet package list
dotnet package list --outdated
dotnet package list --outdated --highest-minor
dotnet package list --deprecated --include-transitive
[net10.0]:
Top-level Package Requested Resolved Latest
> NuGet.Protocol 5.11.2 5.11.2 7.9.0
[net10.0]:
Top-level Package Requested Resolved Latest
> NuGet.Protocol 5.11.2 5.11.2 5.11.7
[net10.0]:
Transitive Package Resolved Reason(s) Alternative
> System.Security.Cryptography.Pkcs 5.0.0 Other,Legacy
--highest-minor and --highest-patch cap "latest" at the current major or minor version — 5.11.7 is the newest
5.x. --outdated, --deprecated and --vulnerable (Auditing Packages for Vulnerabilities)
exclude each other; --include-transitive adds transitive packages; --include-prerelease considers prereleases for
"latest"; -f restricts to a framework (or framework/RID); -s/--configfile choose the sources queried. These
queries go to every configured source — package source mapping does not filter them
(Package Sources and Source Mapping).
For scripts, --format json:
dotnet package list --format json --output-version 1
{
"version": 1,
"parameters": "",
"projects": [
{
"path": "~/audit/Audit.csproj",
"frameworks": [
{
"framework": "net10.0",
"topLevelPackages": [
{
"id": "NuGet.Protocol",
"requestedVersion": "5.11.2",
"resolvedVersion": "5.11.2"
}
]
}
]
}
]
}
list restores first unless --no-restore is given.
Source: dotnet package list.
dotnet package remove, search, update and download
-
remove <id>— removes thePackageReference(--project,--file,--interactive). -
search <term>(SDK 8.0.2xx) — searches sources:--source(repeatable),--take/--skip,--exact-match(all versions of one ID; ignores take and skip),--prerelease,--format table|json,--configfile,--verbosity normal|minimal|detailed. -
update [<ids>](.NET 10) — updates to the latest version, or with--vulnerableto the lowest version without known vulnerabilities. It restores to validate the result, so warnings-as-errors can block it (Solutions, References and Packages). -
download <id>[@version](SDK 10.0.2xx) — downloads into a folder without a project:-o,-s,--configfile,--prerelease,--allow-insecure-connections.
The NuGet 7.3 release notes call the last one dotnet nuget download ("Add dotnet nuget download command"); the shipped
command is dotnet package download, and the dotnet-nuget-download documentation URL returns 404.
dotnet nuget commands
| Command | Purpose and page |
|---|---|
|
Paths that bring a package into the graph; also accepts a |
|
List or clear the local folders (Global Packages and Cache Folders). |
|
Manage sources (Package Sources and Source Mapping). |
|
Read and write |
|
Check package signatures (Signed Packages and Trust Policies). |
|
Manage trusted signers (same page). |
|
Publishing; |
Several dotnet nuget commands list a --force-english-output option in their help; passed to dotnet nuget why, it
was rejected ("Unrecognized command or argument '--force-english-output'").
The dotnet nuget config pages say "applies to .NET 8.0.2xx SDK and later", while the NuGet 6.10 release notes — NuGet 6.10 shipped with SDK 8.0.3xx — list the command as new ("add dotnet nuget config command"). Treat 8.0.3xx as
the safe minimum.
Verb-first equivalents
For SDK 9 and earlier scripts (they still work on SDK 10):
| SDK 10 | Older form |
|---|---|
|
|
|
|
|
|
|
|
|
(none) |
SDK 9.0.319 already accepted the noun-first add, list, remove and search
(Solutions, References and Packages).
Common mistakes
-
dotnet package add X -v detailed—-vis--versionhere. -
--add-source-style options in scripts for repositories with source mapping — map the source. -
Parsing the table output of
list— use--format json --output-version 1. -
Expecting
--outdatedto respect source mapping — it queries every source.