Skip to main content
Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.Contact Sales

Upgrade NuGet package version

Recipe IDOpenRewrite.CSharp.Recipes.UpgradeNuGetPackageVersion
ArtifactOpenRewrite.Recipes.CSharp.Core

Upgrades the version of a NuGet <PackageReference> or <PackageVersion> in .csproj and Directory.Packages.props files. Handles property references by updating the property value instead of the version attribute. Uses NuGet.Versioning for correct version semantics.

Single recipeOpenRewriteModerne Proprietary License
Try in PlatformTry this recipe in the Moderne platform. Not a user yet? You’ll get a no-setup demo environment, with nothing to install or configure.

Options

4 parameters
2 required2 optional
ParameterExampleTypeRequired
NewVersion14.0.0StringRequired
An exact version number, or a NuGet version range (e.g. '[14.0,)' for >= 14.0). Use 'latest' to upgrade to the latest available version from NuGet sources.
PackageNameNewtonsoft.JsonStringRequired
The NuGet package name to upgrade. Supports glob patterns.
IncludePrereleaseBooleanOptional
Whether to include prerelease versions when resolving 'latest' or ranges.
RegenerateMarkerBooleanOptional
Whether 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.

Usage

Run this recipe

In order to run C# recipes, you will need to use the Moderne CLI.

Once the CLI is installed, you can install this C# recipe package by running the following command:

Install the recipe package
mod config recipes nuget install OpenRewrite.Recipes.CSharp.Core

Then, you can run the recipe via:

Run the recipe
mod run . --recipe OpenRewrite.CSharp.Recipes.UpgradeNuGetPackageVersion