← All recipes
Moderne licensed

Add NuGet package reference

Recipe IDOpenRewrite.CSharp.Recipes.AddNuGetPackageReferenceArtifactOpenRewrite.Recipes.CSharp.Core

Adds a <PackageReference> element to .csproj files if not already present.

Single recipeProprietary

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe OpenRewrite.CSharp.Recipes.AddNuGetPackageReference --recipe-option "PackageName=Newtonsoft.Json"

If the recipe isn’t available locally, install it with:

mod config recipes nuget install OpenRewrite.Recipes.CSharp.Core

Options

NameTypeDescription
PackageNamerequiredStringThe NuGet package name to add.
e.g. Newtonsoft.Json
VersionStringThe package version to add. If omitted, no Version attribute is set.
e.g. 13.0.3
RegenerateMarkerBooleanWhether to re-run dotnet restore after the edit to refresh the project's MSBuildProject marker. Defaults to true. Composite recipes that chain multiple csproj-mutating steps may set this to false on intermediate steps and finalize once with EnsureCsprojAttestation.