dotnet add package

This article applies to: ✔️ .NET Core 3.1 SDK and later versions


dotnet add package - Adds or updates a package reference in a project file.


dotnet add [<PROJECT>] package <PACKAGE_NAME>
    [-f|--framework <FRAMEWORK>] [--interactive]
    [-n|--no-restore] [--package-directory <PACKAGE_DIRECTORY>]
    [--prerelease] [-s|--source <SOURCE>] [-v|--version <VERSION>]

dotnet add package -h|--help


The dotnet add package command provides a convenient option to add or update a package reference in a project file. When you run the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes and the package isn't referenced in the project file, a <PackageReference> element is added to the project file. If the check passes and the package is already referenced in the project file, the <PackageReference> element is updated to the latest compatible version. After the project file is updated, dotnet restore is run.

For example, adding Microsoft.EntityFrameworkCore to ToDo.csproj produces output similar to the following example:

  Determining projects to restore...
  Writing C:\Users\username\AppData\Local\Temp\tmp24A8.tmp
info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore' into project 'C:\ToDo\ToDo.csproj'.
info :   CACHE
info :   GET
info :   CACHE
info :   CACHE
info :   CACHE
info :   NotFound 257ms
info : Restoring packages for C:\ToDo\ToDo.csproj...
info : Package 'Microsoft.EntityFrameworkCore' is compatible with all the specified frameworks in project 'C:\ToDo\ToDo.csproj'.
info : PackageReference for package 'Microsoft.EntityFrameworkCore' version '6.0.4' added to file 'C:\ToDo\ToDo.csproj'.
info : Writing assets file to disk. Path: C:\ToDo\obj\project.assets.json
log  : Restored C:\ToDo\ToDo.csproj (in 171 ms).

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

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.4" />

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.



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


    The package reference to add.


  • -f|--framework <FRAMEWORK>

    Adds a package reference only when targeting a specific framework.

  • -?|-h|--help

    Prints out a description of how to use the command.

  • --interactive

    Allows the command to stop and wait for user input or action. For example, to complete authentication.

  • -n|--no-restore

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

  • --package-directory <PACKAGE_DIRECTORY>

    The directory where to restore the packages. The default package restore location is %userprofile%\.nuget\packages 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. Available since .NET Core 5 SDK

  • -s|--source <SOURCE>

    The URI of the NuGet package source to use during the restore operation.

  • -v|--version <VERSION>

    Version of the package. See NuGet package versioning.


  • Add Microsoft.EntityFrameworkCore NuGet package to a project:

    dotnet add package Microsoft.EntityFrameworkCore
  • 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

See also