pcpm add
Add a direct dependency.
pcpm add is the command you’ll use most often. It declares a
direct dependency in your workspace.
pcpm add <package>[@<version>] [options]
What it does
- Resolves a version for
<package>. By default, the latest stable on the feed. Override with<package>@<version>,--version <v>, or--version-range <r>. - Writes the version into
Directory.Packages.propsas a<PackageVersion />entry. - Adds a
<PackageReference Include="…" />entry to one or more.csprojfiles. - Runs
pcpm installto materialise the change in the store (skip with--no-install).
Options
| Flag | Effect |
|---|---|
<package> | The package id, e.g. Serilog. |
<package>@<version> | Pin a specific version inline. |
--version <v> | Pin a specific version. |
--version-range <r> | Pin a version range (e.g. 3.0.*, [3.0, 4.0)). |
--project <path> | Add to a specific .csproj only. Repeatable. |
--all-projects | Add to every project in the workspace (default). |
--no-install | Skip the implicit pcpm install. |
--prerelease | Include pre-release versions in the resolution. |
--source <url> | Use a specific feed for this resolution. |
Examples
# Add the latest stable of Serilog
pcpm add Serilog
# Pin a specific version
pcpm add Serilog@3.1.1
# Add to a single project
pcpm add Serilog --project src/Api/Api.csproj
# Add to a subset of projects
pcpm add Microsoft.Extensions.Hosting \
--project src/Api/Api.csproj \
--project src/Worker/Worker.csproj
# Pin a version range
pcpm add Newtonsoft.Json --version-range "13.0.*"
# Add from a private feed
pcpm add Contoso.Internal --source https://pkgs.contoso.com/v3/index.json
Implicit install
By default, pcpm add finishes with pcpm install so the new
dependency is on disk and ready to use by the time your prompt
comes back. In a monorepo, this means the lockfile is also
updated and committed. The implicit install is a feature, not
a bug — it catches typos in the package id immediately.
If you want to add many packages in one go and only install once, chain them:
pcpm add Serilog --no-install
pcpm add Microsoft.Extensions.Hosting --no-install
pcpm add Serilog.Sinks.Console --no-install
pcpm install
See also
pcpm remove— inverse operation.pcpm install— the workhorse.- Configuration — for private feeds.