dotnet-add-package(1)
π dotnet-add-package(1) β the manual, but make it cute β¨
okay bestie, welcome to the dotnet-add-package page from the .NET Documentation β¨ this one lives in section 1 of the manual, and it's lowkey one of the most useful little gremlins in the whole .NET CLI.
This article applies to: βοΈ .NET Core 3.1 SDK and later versions
πΈ NAME πΈ
dotnet-add-package β adds or updates a package reference in a project file. that's it, that's the job, and it does it flawlessly π
π SYNOPSIS π
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
π¦ DESCRIPTION π¦
so the dotnet add package command is literally the convenient way to add or update a package reference in a project file. no cap. π«Ά
when you run it, there's a compatibility check first β it makes sure the package actually vibes with the frameworks in your project. if the check passes and the package isn't referenced in the project file yet, a <PackageReference> element gets added. if the check passes and the package is already referenced, then the existing <PackageReference> element gets updated to the latest compatible version. and after the project file is updated, dotnet restore runs. periodt.
for example, adding Microsoft.EntityFrameworkCore to ToDo.csproj produces output similar to this:
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 https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/index.json
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
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/page/0.0.1-alpha/3.1.3.json
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore/page/3.1.4/7.0.0-preview.2.22153.1.json
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
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
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).
and now the ToDo.csproj file contains a <PackageReference> element for the referenced package π
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.4" />
β¨ Implicit restore β¨
you do not have to run dotnet restore yourself, bestie, because it's run implicitly by every command that needs a restore to happen β like dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. if you wanna turn that off, use the --no-restore option. π
that said, dotnet restore is still genuinely useful in certain scenarios where explicitly restoring makes sense β like continuous integration builds in Azure DevOps Services, or in build systems that need to explicitly control when the restore occurs.
for info about how to manage NuGet feeds, go read the dotnet restore documentation. iykyk π
π ARGUMENTS π
PROJECTβ specifies the project file. if you don't give one, the command goes looking for it in the current directory. she's self-sufficient like that π§PACKAGE_NAMEβ the package reference you wanna add. the whole point of the operation π
π OPTIONS π
-f|--framework <FRAMEWORK>β only adds the package reference when you're targeting a specific framework.-?|-h|--helpβ prints out a description of how to use the command. your bestie when you're lost π«Ά--interactiveβ lets the command stop and wait for user input or action. like, for example, to complete authentication.-n|--no-restoreβ adds a package reference without performing a restore preview and compatibility check. skipping the vibe check, risky but iconic π--package-directory <PACKAGE_DIRECTORY>β the directory where the packages get restored to. the default package restore location is%userprofile%\.nuget\packageson Windows, and~/.nuget/packageson macOS and Linux. for more info, 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.
π₯ EXAMPLES π₯
- add the
Microsoft.EntityFrameworkCoreNuGet 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 https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
π SEE ALSO π
- Managing the global packages, cache, and temp folders in NuGet
- NuGet package versioning
okay that's the whole page, you ate it up, go add some packages π
signing off from dotnet-add-package(1), dated 2024-10-02, brought to you by the .NET Documentation crew πβ¨
π¦ where this page comes from
- fedora 43: dotnet-host 9.0.8-1.fc43 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- ubuntu questing: dotnet-host-9.0 9.0.17-0ubuntu1~25.10.1
- ubuntu questing: dotnet-host-9.0 9.0.9-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms