dotnet add package

This topic applies to: ✓ .NET Core SDK 1.x .NET Core SDK 2.x


dotnet add package - Adds a package reference to a project file.


dotnet add [<PROJECT>] package <PACKAGE_NAME> [-h|--help] [-f|--framework] [-n|--no-restore] [--package-directory] [-s|--source] [-v|--version] [--interactive]


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 <PackageReference> element is added to the project file and dotnet restore is run.


Starting with .NET Core 2.0, 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 and dotnet run. It's still a valid command in certain scenarios where doing an explicit restore makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control the time at which the restore occurs.

For example, adding Newtonsoft.Json to ToDo.csproj produces output similar to the following example:

  Writing C:\Users\mairaw\AppData\Local\Temp\tmp95A8.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\projects\ToDo\ToDo.csproj'.
log  : Restoring packages for C:\projects\ToDo\ToDo.csproj...
info :   GET
info :   OK 235ms
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\projects\ToDo\ToDo.csproj'.
info : PackageReference for package 'Newtonsoft.Json' version '10.0.3' added to file 'C:\projects\ToDo\ToDo.csproj'.

The ToDo.csproj file now contains a <PackageReference> element for the referenced package.

<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />



Specifies the project file. If not specified, the command searches the current directory for one.


The package reference to add.



Prints out a short help for the command.

-f|--framework <FRAMEWORK>

Adds a package reference only when targeting a specific framework.


Adds a package reference without performing a restore preview and compatibility check.

--package-directory <PACKAGE_DIRECTORY>

Restores the package to the specified directory.

-s|--source <SOURCE>

Uses a specific NuGet package source during the restore operation.

-v|--version <VERSION>

Version of the package.


Allows the command to stop and wait for user input or action (for example to complete authentication). Since .NET Core 2.1.400.


Add Newtonsoft.Json NuGet package to a project:

dotnet add package Newtonsoft.Json

Add a specific version of a package to a project:

dotnet add ToDo.csproj package Microsoft.Azure.DocumentDB.Core -v 1.0.0

Add a package using a specific NuGet source:

dotnet add package Microsoft.AspNetCore.StaticFiles -s