Module has dependency
org.openrewrite.csharp.search.ModuleHasDependencyArtifactorg.openrewrite:rewrite-csharpSearches for .NET projects that have a NuGet package dependency matching the specified package id. Places a SearchResult marker on all sources within a project with a matching dependency. A source belongs to the project file (.csproj, .vbproj, .fsproj) in its nearest enclosing directory. This recipe is intended to be used as a precondition for other recipes. For example this could be used to limit the application of a migration to only projects that use a specific version of a package. If the search result you want is instead just the project file referencing the package, use the FindNuGetPackageReference recipe instead.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
settings.gradle.kts
pluginManagement {
repositories {
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
gradlePluginPortal()
}
}
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.csharp.search.ModuleHasDependency")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite:rewrite-csharp:8.93.8")
}
Then run
./gradlew rewriteRunThis recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.csharp.search.ModuleHasDependency --recipe-option "packageIdPattern=Microsoft.EntityFrameworkCore*"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-csharp:RELEASEOptions
| Name | Type | Description |
|---|---|---|
packageIdPatternrequired | String | Package id glob pattern used to match dependencies. Matching is case-insensitive. e.g. Microsoft.EntityFrameworkCore* |
version | String | Match only dependencies with the specified resolved version. Node-style version selectors may be used. All versions are searched by default. e.g. 8.x |
onlyDirect | Boolean | If enabled, transitive dependencies will not be considered. All dependencies are searched by default. e.g. true |
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats