LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

dotnet-add-package

Add or update a NuGet package reference in a project

TLDR

Add a NuGet package
$ dotnet add package [package_name]
copy
Add specific version
$ dotnet add package [package_name] --version [1.0.0]
copy
Add package to specific project
$ dotnet add [project.csproj] package [package_name]
copy
Add prerelease version
$ dotnet add package [package_name] --prerelease
copy
Add from specific source
$ dotnet add package [package_name] --source [https://api.nuget.org/v3/index.json]
copy
Add package targeting a specific framework
$ dotnet add package [package_name] --framework [net8.0]
copy

SYNOPSIS

dotnet add [project] package packagename [options_]

DESCRIPTION

dotnet add package adds a NuGet package reference to a project file and runs a compatibility check. It modifies the .csproj or .fsproj file to include a PackageReference element, making the dependency trackable in version control.If the package is already referenced, it updates the reference to the latest compatible version. The command runs an implicit dotnet restore after adding the reference unless --no-restore is specified. Projects using Central Package Management (CPM) will have the PackageVersion element updated in the Directory.Packages.props file.

PARAMETERS

-v, --version version

Specific version to install.
--prerelease
Allow prerelease packages to be installed.
-f, --framework framework
Add a package reference only when targeting a specific framework.
-s, --source source
NuGet package source URI to use during restore.
-n, --no-restore
Add reference without performing a restore preview and compatibility check.
--package-directory dir
Directory to restore packages to.
--interactive
Allow the command to stop and wait for user input or action.

SEE ALSO

Copied to clipboard
Kai