See Ways to install NuGet packages. To work with NuGet, as a package consumer or creator, you can use command-line interface (CLI) tools as well as NuGet features in Visual Studio. This article briefly outlines the capabilities of the different tools, how to install them, and their comparative feature availability. To use or install package manually, go to Tools- Options- NuGet Package Manager- Package Sources. Click the Add button, choose the Source, and don't forget to click 'Update' as it will update the folder location for your packages, edit your desired Name of your package source if.
-->This article applies to: ✔️ .NET Core 2.x SDK and later versions
Name
dotnet add package
- Adds a package reference to a project file.
Dotnet Cli Install Package
Synopsis
Description
The dotnet add package
command provides a convenient option to add a package reference to a project file. After running the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes, a element is added to the project file and dotnet restore is run.
For example, adding Newtonsoft.Json
to ToDo.csproj produces output similar to the following example:
The ToDo.csproj file now contains a element for the referenced package.
Implicit restore
You don't have to run dotnet restore
because it's run implicitly by all commands that require a restore to occur, such as dotnet new
, dotnet build
, dotnet run
, dotnet test
, dotnet publish
, and dotnet pack
. To disable implicit restore, use the --no-restore
option.
The dotnet restore
command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
For information about how to manage NuGet feeds, see the dotnet restore
documentation.
Arguments
PROJECT
Specifies the project file. If not specified, the command searches the current directory for one.
PACKAGE_NAME
The package reference to add.
Install Nuget Package Dotnet Cli Commands
Options
Dotnet Install Local Nuget Package
-f|--framework
Adds a package reference only when targeting a specific framework.
-h|--help
Prints out a short help for the command.
--interactive
Allows the command to stop and wait for user input or action (for example, to complete authentication). Available since .NET Core 2.1 SDK, version 2.1.400 or later.
-n|--no-restore
Adds a package reference without performing a restore preview and compatibility check.
--package-directory
The directory where to restore the packages. The default package restore location is
%userprofile%.nugetpackages
on Windows and~/.nuget/packages
on macOS and Linux. For more information, see Managing the global packages, cache, and temp folders in NuGet.--prerelease
Allows prerelease packages to be installed.
-s|--source
The URI of the NuGet package source to use during the restore operation.
-v|--version
Version of the package. See NuGet package versioning.
Examples
Name
dotnet add package
- Adds a package reference to a project file.
Dotnet Cli Install Package
Synopsis
Description
The dotnet add package
command provides a convenient option to add a package reference to a project file. After running the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes, a element is added to the project file and dotnet restore is run.
For example, adding Newtonsoft.Json
to ToDo.csproj produces output similar to the following example:
The ToDo.csproj file now contains a element for the referenced package.
Implicit restore
You don't have to run dotnet restore
because it's run implicitly by all commands that require a restore to occur, such as dotnet new
, dotnet build
, dotnet run
, dotnet test
, dotnet publish
, and dotnet pack
. To disable implicit restore, use the --no-restore
option.
The dotnet restore
command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
For information about how to manage NuGet feeds, see the dotnet restore
documentation.
Arguments
PROJECT
Specifies the project file. If not specified, the command searches the current directory for one.
PACKAGE_NAME
The package reference to add.
Install Nuget Package Dotnet Cli Commands
Options
Dotnet Install Local Nuget Package
-f|--framework
Adds a package reference only when targeting a specific framework.
-h|--help
Prints out a short help for the command.
--interactive
Allows the command to stop and wait for user input or action (for example, to complete authentication). Available since .NET Core 2.1 SDK, version 2.1.400 or later.
-n|--no-restore
Adds a package reference without performing a restore preview and compatibility check.
--package-directory
The directory where to restore the packages. The default package restore location is
%userprofile%.nugetpackages
on Windows and~/.nuget/packages
on macOS and Linux. For more information, see Managing the global packages, cache, and temp folders in NuGet.--prerelease
Allows prerelease packages to be installed.
-s|--source
The URI of the NuGet package source to use during the restore operation.
-v|--version
Version of the package. See NuGet package versioning.
Examples
Dotnet Install Nuget Package
Add
Newtonsoft.Json
NuGet package to a project:Add a specific version of a package to a project:
Add a package using a specific NuGet source: