Add NuGet package reference when namespace is used
ProprietaryAdds a <PackageReference> to a .csproj only when a C# source file in the same project directory has a using directive that starts with the trigger namespace prefix. Useful for paired add-package-when-type-is-used migrations.
OpenRewrite. Recipes. CSharp. Migration. Dotnet. AddNuGetPackageReferenceIfTypeUsedRequired
The NuGet package name to add.
Optional
The package version to add. If omitted, no Version attribute is set.
The package is added if any C# source file in the same project directory has a using directive whose namespace starts with this prefix. At least one of Trigger namespace prefix or Trigger type FQN must be set.
The package is added if any C# source file in the same project directory has a fully-qualified reference to this type. Useful for types that live in a namespace that's already in scope via existing usings (so the using directive doesn't change). At least one of Trigger namespace prefix or Trigger type FQN must be set.
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.
mod run . --recipe= OpenRewrite. Recipes. CSharp. Migration. Dotnet. AddNuGetPackageReferenceIfTypeUsed \
-P PackageName= Newtonsoft. JsonInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.