1dotnet-add-package(1) .NET Documentation dotnet-add-package(1)
2
3
4
6 This article applies to: ✔️ .NET Core 3.1 SDK and later versions
7
9 dotnet-add-package - Adds or updates a package reference in a project
10 file.
11
13 dotnet add [<PROJECT>] package <PACKAGE_NAME>
14 [-f|--framework <FRAMEWORK>] [--interactive]
15 [-n|--no-restore] [--package-directory <PACKAGE_DIRECTORY>]
16 [--prerelease] [-s|--source <SOURCE>] [-v|--version <VERSION>]
17
18 dotnet add package -h|--help
19
21 The dotnet add package command provides a convenient option to add or
22 update a package reference in a project file. When you run the com‐
23 mand, there’s a compatibility check to ensure the package is compatible
24 with the frameworks in the project. If the check passes and the pack‐
25 age isn’t referenced in the project file, a <PackageReference> element
26 is added to the project file. If the check passes and the package is
27 already referenced in the project file, the <PackageReference> element
28 is updated to the latest compatible version. After the project file is
29 updated, dotnet restore is run.
30
31 For example, adding Microsoft.EntityFrameworkCore to ToDo.csproj pro‐
32 duces output similar to the following example:
33
34 Determining projects to restore...
35 Writing C:\Users\username\AppData\Local\Temp\tmp24A8.tmp
36 info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore' into project 'C:\ToDo\ToDo.csproj'.
37 info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/index.json
38 info : GET https://pkgs.dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_packaging/516521bf-6417-457e-9a9c-0a4bdfde03e7/nuget/v3/registrations2-semver2/microsoft.entityframeworkcore/index.json
39 info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/page/0.0.1-alpha/3.1.3.json
40 info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/page/3.1.4/7.0.0-preview.2.22153.1.json
41 info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/page/7.0.0-preview.3.22175.1/7.0.0-preview.3.22175.1.json
42 info : NotFound https://pkgs.dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_packaging/516521bf-6417-457e-9a9c-0a4bdfde03e7/nuget/v3/registrations2-semver2/microsoft.entityframeworkcore/index.json 257ms
43 info : Restoring packages for C:\ToDo\ToDo.csproj...
44 info : Package 'Microsoft.EntityFrameworkCore' is compatible with all the specified frameworks in project 'C:\ToDo\ToDo.csproj'.
45 info : PackageReference for package 'Microsoft.EntityFrameworkCore' version '6.0.4' added to file 'C:\ToDo\ToDo.csproj'.
46 info : Writing assets file to disk. Path: C:\ToDo\obj\project.assets.json
47 log : Restored C:\ToDo\ToDo.csproj (in 171 ms).
48
49 The ToDo.csproj file now contains a <PackageReference> element for the
50 referenced package.
51
52 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.4" />
53
54 Implicit restore
55 You don’t have to run dotnet restore because it’s run implicitly by all
56 commands that require a restore to occur, such as dotnet new, dotnet
57 build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To
58 disable implicit restore, use the --no-restore option.
59
60 The dotnet restore command is still useful in certain scenarios where
61 explicitly restoring makes sense, such as continuous integration builds
62 in Azure DevOps Services or in build systems that need to explicitly
63 control when the restore occurs.
64
65 For information about how to manage NuGet feeds, see the dotnet restore
66 documentation.
67
69 • PROJECT
70
71 Specifies the project file. If not specified, the command searches
72 the current directory for one.
73
74 • PACKAGE_NAME
75
76 The package reference to add.
77
79 • -f|--framework <FRAMEWORK>
80
81 Adds a package reference only when targeting a specific framework.
82
83 • -?|-h|--help
84
85 Prints out a description of how to use the command.
86
87 • --interactive
88
89 Allows the command to stop and wait for user input or action. For
90 example, to complete authentication.
91
92 • -n|--no-restore
93
94 Adds a package reference without performing a restore preview and
95 compatibility check.
96
97 • --package-directory <PACKAGE_DIRECTORY>
98
99 The directory where to restore the packages. The default package re‐
100 store location is %userprofile%\.nuget\packages on Windows and
101 ~/.nuget/packages on macOS and Linux. For more information, see Man‐
102 aging the global packages, cache, and temp folders in NuGet.
103
104 • --prerelease
105
106 Allows prerelease packages to be installed. Available since .NET
107 Core 5 SDK
108
109 • -s|--source <SOURCE>
110
111 The URI of the NuGet package source to use during the restore opera‐
112 tion.
113
114 • -v|--version <VERSION>
115
116 Version of the package. See NuGet package versioning.
117
119 • Add Microsoft.EntityFrameworkCore NuGet package to a project:
120
121 dotnet add package Microsoft.EntityFrameworkCore
122
123 • Add a specific version of a package to a project:
124
125 dotnet add ToDo.csproj package Microsoft.Azure.DocumentDB.Core -v 1.0.0
126
127 • Add a package using a specific NuGet source:
128
129 dotnet add package Microsoft.AspNetCore.StaticFiles -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
130
132 • Managing the global packages, cache, and temp folders in NuGet
133
134 • NuGet package versioning
135
136
137
138 2022-10-10 dotnet-add-package(1)