1(1)                                  .NET                                  (1)
2
3
4

dotnet add package

6       This article applies to: ✔️ .NET Core 2.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>
13                  [-f|--framework <FRAMEWORK>] [--interactive]
14                  [-n|--no-restore] [--package-directory <PACKAGE_DIRECTORY>]
15                  [--prerelease] [-s|--source <SOURCE>] [-v|--version <VERSION>]
16
17              dotnet add package -h|--help
18

DESCRIPTION

20       The  dotnet  add  package command provides a convenient option to add a
21       package reference to  a  project  file.   After  running  the  command,
22       there’s  a compatibility check to ensure the package is compatible with
23       the frameworks in the project.  If the check passes,  a  <PackageRefer‐
24       ence> element is added to the project file and dotnet restore is run.
25
26       For example, adding Newtonsoft.Json to ToDo.csproj produces output sim‐
27       ilar to the following example:
28
29              Writing C:\Users\me\AppData\Local\Temp\tmp95A8.tmp
30              info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\projects\ToDo\ToDo.csproj'.
31              log  : Restoring packages for C:\Temp\projects\consoleproj\consoleproj.csproj...
32              info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
33              info :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 79ms
34              info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/12.0.1/newtonsoft.json.12.0.1.nupkg
35              info :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/12.0.1/newtonsoft.json.12.0.1.nupkg 232ms
36              log  : Installing Newtonsoft.Json 12.0.1.
37              info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\projects\ToDo\ToDo.csproj'.
38              info : PackageReference for package 'Newtonsoft.Json' version '12.0.1' added to file 'C:\projects\ToDo\ToDo.csproj'.
39
40       The ToDo.csproj file now contains a <PackageReference> element for  the
41       referenced package.
42
43              <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
44
45   Implicit restore
46       You don’t have to run dotnet restore because it’s run implicitly by all
47       commands that require a restore to occur, such as  dotnet  new,  dotnet
48       build,  dotnet  run,  dotnet test, dotnet publish, and dotnet pack.  To
49       disable implicit restore, use the --no-restore option.
50
51       The dotnet restore command is still useful in certain  scenarios  where
52       explicitly restoring makes sense, such as continuous integration builds
53       in Azure DevOps Services or in build systems that  need  to  explicitly
54       control when the restore occurs.
55
56       For information about how to manage NuGet feeds, see the dotnet restore
57       documentation.
58
59   Arguments
60PROJECT
61
62         Specifies the project file.  If not specified, the  command  searches
63         the current directory for one.
64
65PACKAGE_NAME
66
67         The package reference to add.
68

OPTIONS

70-f|--framework <FRAMEWORK>
71
72         Adds a package reference only when targeting a specific framework.
73
74-?|-h|--help
75
76         Prints out a description of how to use the command.
77
78--interactive
79
80         Allows  the  command  to stop and wait for user input or action.  For
81         example, to complete authentication.
82
83-n|--no-restore
84
85         Adds a package reference without performing  a  restore  preview  and
86         compatibility check.
87
88--package-directory <PACKAGE_DIRECTORY>
89
90         The directory where to restore the packages.  The default package re‐
91         store  location  is  %userprofile%\.nuget\packages  on  Windows   and
92         ~/.nuget/packages on macOS and Linux.  For more information, see Man‐
93         aging the global packages, cache, and temp folders in NuGet.
94
95--prerelease
96
97         Allows prerelease packages to be  installed.   Available  since  .NET
98         Core 5 SDK
99
100-s|--source <SOURCE>
101
102         The  URI of the NuGet package source to use during the restore opera‐
103         tion.
104
105-v|--version <VERSION>
106
107         Version of the package.  See NuGet package versioning.
108

EXAMPLES

110       • Add Newtonsoft.Json NuGet package to a project:
111
112                dotnet add package Newtonsoft.Json
113
114       • Add a specific version of a package to a project:
115
116                dotnet add ToDo.csproj package Microsoft.Azure.DocumentDB.Core -v 1.0.0
117
118       • Add a package using a specific NuGet source:
119
120                dotnet add package Microsoft.AspNetCore.StaticFiles -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
121
122   See also
123       • Managing the global packages, cache, and temp folders in NuGet
124
125       • NuGet package versioning
126
127
128
129                                                                           (1)
Impressum