1dotnet add package command(1)      .NET Core     dotnet add package command(1)
2
3
4

dotnet add package

6       This article applies to: ✓ .NET Core 1.x SDK and later versions
7

NAME

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

SYNOPSIS

12       dotnet  add [<PROJECT>] package <PACKAGE_NAME> [-h|--help] [-f|--frame‐
13       work]    [--interactive]    [-n|--no-restore]     [--package-directory]
14       [-s|--source] [-v|--version]
15

DESCRIPTION

17       The  dotnet  add  package command provides a convenient option to add a
18       package reference to  a  project  file.   After  running  the  command,
19       there’s  a compatibility check to ensure the package is compatible with
20       the frameworks in the project.  If the check passes,  a  <PackageRefer‐
21       ence> element is added to the project file and dotnet restore is run.
22
23       For example, adding Newtonsoft.Json to ToDo.csproj produces output sim‐
24       ilar to the following example:
25
26                Writing C:\Users\mairaw\AppData\Local\Temp\tmp95A8.tmp
27              info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\projects\ToDo\ToDo.csproj'.
28              log  : Restoring packages for C:\Temp\projects\consoleproj\consoleproj.csproj...
29              info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
30              info :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 79ms
31              info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/12.0.1/newtonsoft.json.12.0.1.nupkg
32              info :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/12.0.1/newtonsoft.json.12.0.1.nupkg 232ms
33              log  : Installing Newtonsoft.Json 12.0.1.
34              info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\projects\ToDo\ToDo.csproj'.
35              info : PackageReference for package 'Newtonsoft.Json' version '12.0.1' added to file 'C:\projects\ToDo\ToDo.csproj'.
36
37       The ToDo.csproj file now contains a <PackageReference> element for  the
38       referenced package.
39
40              <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
41
42   Arguments
43       · PROJECT
44
45         Specifies  the  project file.  If not specified, the command searches
46         the current directory for one.
47
48       · PACKAGE_NAME
49
50         The package reference to add.
51

OPTIONS

53       · -f|--framework <FRAMEWORK>
54
55         Adds a package reference only when targeting a specific framework.
56
57       · -h|--help
58
59         Prints out a short help for the command.
60
61       · --interactive
62
63         Allows the command to stop and wait for user input or action (for ex‐
64         ample,  to  complete  authentication).  Available since .NET Core 2.1
65         SDK, version 2.1.400 or later.
66
67       · -n|--no-restore
68
69         Adds a package reference without performing  a  restore  preview  and
70         compatibility check.
71
72       · --package-directory <PACKAGE_DIRECTORY>
73
74         The directory where to restore the packages.  The default package re‐
75         store  location  is  %userprofile%\.nuget\packages  on  Windows   and
76         ~/.nuget/packages on macOS and Linux.  For more information, see Man‐
77         aging the global packages, cache, and temp folders in NuGet.
78
79       · -s|--source <SOURCE>
80
81         The NuGet package source to use during the restore operation.
82
83       · -v|--version <VERSION>
84
85         Version of the package.  See NuGet package versioning.
86

EXAMPLES

88       · Add Newtonsoft.Json NuGet package to a project:
89
90                dotnet add package Newtonsoft.Json
91
92       · Add a specific version of a package to a project:
93
94                dotnet add ToDo.csproj package Microsoft.Azure.DocumentDB.Core -v 1.0.0
95
96       · Add a package using a specific NuGet source:
97
98                dotnet add package Microsoft.AspNetCore.StaticFiles -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
99
100   See also
101       · Managing the global packages, cache, and temp folders in NuGet
102
103       · NuGet package versioning
104
105
106
107                                                 dotnet add package command(1)
Impressum