@@ -307,53 +307,34 @@ class BaseNuGet extends Exec {
307307 folder. mkdirs()
308308
309309 def nugetUrl = getNugetDownloadLink()
310-
311310 project. logger. info " Downloading NuGet from $nugetUrl ..."
312311
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 )
312+ new URL (nugetUrl). withInputStream {
313+ inputStream ->
314+ localNuget. withOutputStream { outputStream ->
315+ outputStream << inputStream
337316 }
338- } catch (Exception e2) {
339- throw new RuntimeException (" Failed to download NuGet from both $nugetUrl and $fallbackUrl : ${ e2.message} " , e2)
340- }
317+ }
318+
319+ // Make the file executable on Unix systems (required for Mono)
320+ if (! isFamily(FAMILY_WINDOWS )) {
321+ localNuget. setExecutable(true , false )
341322 }
342323 }
343324 localNuget
344325 }
345326
346327 @Internal
347328 protected String getNugetDownloadLink () {
329+ // If a custom URL is provided, use it
348330 if (nugetExePath != null && ! nugetExePath. empty && nugetExePath. startsWith(" http" )) {
349331 project. logger. debug(" Nuget url path is resolved from property 'nugetExePath'" )
350-
351332 return nugetExePath
352333 }
353334
354- def exeName = project . extensions . nuget . version < ' 3.4.4 ' ? ' nuget.exe ' : ' NuGet.exe '
355-
356- return " https://dist.nuget.org/win-x86-commandline/v ${ project.extensions. nuget.version } / ${ exeName } "
335+ // Use /latest/ endpoint for simplicity - always gets the latest version
336+ // This is more reliable than versioned URLs which may not exist
337+ return " https://dist.nuget.org/win-x86-commandline/latest/ nuget.exe "
357338 }
358339
359340 @Internal
0 commit comments