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.
75
76       · -s|--source <SOURCE>
77
78         The NuGet package source to use during the restore operation.
79
80       · -v|--version <VERSION>
81
82         Version of the package.
83

EXAMPLES

85       · Add Newtonsoft.Json NuGet package to a project:
86
87                dotnet add package Newtonsoft.Json
88
89       · Add a specific version of a package to a project:
90
91                dotnet add ToDo.csproj package Microsoft.Azure.DocumentDB.Core -v 1.0.0
92
93       · Add a package using a specific NuGet source:
94
95                dotnet add package Microsoft.AspNetCore.StaticFiles -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
96
97
98
99                                                 dotnet add package command(1)
Impressum