Skip to content

Commit 9f66264

Browse files
committed
Add fallback to /latest/ nuget.exe download URL and make file executable
- Add fallback to https://dist.nuget.org/win-x86-commandline/latest/nuget.exe if versioned URL fails - Make downloaded nuget.exe executable on Unix systems (required for Mono execution) - Improves reliability when specific version URLs are unavailable - Based on user suggestion for downloading nuget.exe
1 parent a863877 commit 9f66264

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/main/groovy/com/ullink/BaseNuGet.groovy

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,34 @@ class BaseNuGet extends Exec {
310310

311311
project.logger.info "Downloading NuGet from $nugetUrl ..."
312312

313-
new URL(nugetUrl).withInputStream {
314-
inputStream ->
315-
localNuget.withOutputStream { outputStream ->
316-
outputStream << inputStream
313+
try {
314+
new URL(nugetUrl).withInputStream {
315+
inputStream ->
316+
localNuget.withOutputStream { outputStream ->
317+
outputStream << inputStream
318+
}
319+
}
320+
// Make the file executable on Unix systems
321+
if (!isFamily(FAMILY_WINDOWS)) {
322+
localNuget.setExecutable(true, false)
323+
}
324+
} catch (Exception e) {
325+
// If versioned URL fails, try /latest/ as fallback
326+
def fallbackUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
327+
project.logger.warn "Failed to download from $nugetUrl, trying fallback: $fallbackUrl (${e.message})"
328+
try {
329+
new URL(fallbackUrl).withInputStream {
330+
inputStream ->
331+
localNuget.withOutputStream { outputStream ->
332+
outputStream << inputStream
333+
}
334+
}
335+
if (!isFamily(FAMILY_WINDOWS)) {
336+
localNuget.setExecutable(true, false)
317337
}
338+
} catch (Exception e2) {
339+
throw new RuntimeException("Failed to download NuGet from both $nugetUrl and $fallbackUrl: ${e2.message}", e2)
340+
}
318341
}
319342
}
320343
localNuget

0 commit comments

Comments
 (0)