Skip to content

Commit 78ee4c1

Browse files
committed
Fix up c# tool staleness on builds
1 parent 75a25e6 commit 78ee4c1

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

rewrite-csharp/build.gradle.kts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ val csharpPack by tasks.registering(Exec::class) {
168168
"/p:Version=$nugetVersion"
169169
)
170170

171-
inputs.dir(csharpDir.resolve("OpenRewrite"))
172-
inputs.dir(csharpDir.resolve("OpenRewrite.Tool"))
171+
// Track only source files — exclude bin/obj build outputs to avoid stale up-to-date checks
172+
inputs.files(fileTree(csharpDir.resolve("OpenRewrite")) { exclude("**/bin/**", "**/obj/**") })
173+
inputs.files(fileTree(csharpDir.resolve("OpenRewrite.Tool")) { exclude("**/bin/**", "**/obj/**") })
173174
inputs.property("version", nugetVersion)
174175
outputs.dir(csharpDir.resolve("dist"))
175176

@@ -231,7 +232,7 @@ val csharpPublishLocal by tasks.registering {
231232
val localsOutput = run(dotnet, "nuget", "locals", "global-packages", "--list")
232233
val cachePath = localsOutput.trim().substringAfter("global-packages: ")
233234

234-
// Install each nupkg into the NuGet cache
235+
// Clear stale entries from all NuGet caches for each package
235236
csharpDir.resolve("dist").listFiles()
236237
?.filter { it.name.endsWith(".nupkg") }
237238
?.forEach { nupkg ->
@@ -241,12 +242,19 @@ val csharpPublishLocal by tasks.registering {
241242
// Find the version part by matching the nugetVersion suffix
242243
val packageId = nameWithoutExt.removeSuffix(".$nugetVersion")
243244

244-
// Clear the specific version from cache
245+
// Clear the specific version from global packages cache
245246
val packageCacheDir = file("$cachePath/${packageId.lowercase()}/$nugetVersion")
246247
if (packageCacheDir.exists()) {
247248
logger.lifecycle("Clearing cached: ${packageCacheDir.absolutePath}")
248249
packageCacheDir.deleteRecursively()
249250
}
251+
252+
// Clear any globally installed tool versions (used by `dotnet tool install -g`)
253+
val toolStoreDir = file("${System.getProperty("user.home")}/.dotnet/tools/.store/${packageId.lowercase()}")
254+
if (toolStoreDir.exists()) {
255+
logger.lifecycle("Clearing tool store: ${toolStoreDir.absolutePath}")
256+
toolStoreDir.deleteRecursively()
257+
}
250258
}
251259

252260
// Create a temp project and add packages to populate the NuGet cache

0 commit comments

Comments
 (0)