2023-10-18 10:25:15 +08:00
|
|
|
# dotnet add package
|
|
|
|
|
|
|
|
> Add or update a .NET package reference in a project file.
|
|
|
|
> More information: <https://learn.microsoft.com/dotnet/core/tools/dotnet-add-package>.
|
|
|
|
|
|
|
|
- Add a package to the project in the current directory:
|
|
|
|
|
|
|
|
`dotnet add package {{package}}`
|
|
|
|
|
|
|
|
- Add a package to a specific project:
|
|
|
|
|
|
|
|
`dotnet add {{path/to/file.csproj}} package {{package}}`
|
|
|
|
|
|
|
|
- Add a specific version of a package to the project:
|
|
|
|
|
2025-04-22 15:48:30 +03:00
|
|
|
`dotnet add package {{package}} {{[-v|--version]}} {{1.0.0}}`
|
2023-10-18 10:25:15 +08:00
|
|
|
|
|
|
|
- Add a package using a specific NuGet source:
|
|
|
|
|
2025-04-22 15:48:30 +03:00
|
|
|
`dotnet add package {{package}} {{[-s|--source]}} {{https://api.nuget.org/v3/index.json}}`
|
2023-10-18 10:25:15 +08:00
|
|
|
|
|
|
|
- Add a package only when targeting a specific framework:
|
|
|
|
|
2025-04-22 15:48:30 +03:00
|
|
|
`dotnet add package {{package}} {{[-f|--framework]}} {{net7.0}}`
|
2023-10-18 10:25:15 +08:00
|
|
|
|
|
|
|
- Add and specify the directory where to restore packages (`~/.nuget/packages` by default):
|
|
|
|
|
|
|
|
`dotnet add package {{package}} --package-directory {{path/to/directory}}`
|