From e0c8b420d1b2b9ed110bd3c382c6d7d7ef89e04a Mon Sep 17 00:00:00 2001 From: Keith Robertson Date: Fri, 17 Nov 2017 18:06:56 -0800 Subject: [PATCH] Update default NuGet to 4.1.0 (#5805) --- .../nuget-task-common/NuGetToolGetter.ts | 41 +++++++++++-------- Tasks/NuGetCommand/Tests/NugetMockHelper.ts | 29 +++++++------ Tasks/NuGetCommand/make.json | 4 ++ Tasks/NuGetCommand/nugetcommandmain.ts | 9 +++- Tasks/NuGetCommand/package.json | 2 +- Tasks/NuGetCommand/task.json | 2 +- Tasks/NuGetCommand/task.loc.json | 2 +- 7 files changed, 56 insertions(+), 33 deletions(-) diff --git a/Tasks/Common/nuget-task-common/NuGetToolGetter.ts b/Tasks/Common/nuget-task-common/NuGetToolGetter.ts index c5e6f7cc80fb..3216eca835f7 100644 --- a/Tasks/Common/nuget-task-common/NuGetToolGetter.ts +++ b/Tasks/Common/nuget-task-common/NuGetToolGetter.ts @@ -22,14 +22,18 @@ enum NuGetReleaseStage const NUGET_TOOL_NAME: string = 'NuGet'; const NUGET_EXE_FILENAME: string = 'nuget.exe'; -const NUGET_VERSION_4_0_0: string = '4.0.0'; +export const FORCE_NUGET_4_0_0: string = 'FORCE_NUGET_4_0_0'; +export const NUGET_VERSION_4_0_0: string = '4.0.0'; +export const NUGET_VERSION_4_0_0_PATH_SUFFIX: string = 'NuGet/4.0.0/'; +export const DEFAULT_NUGET_VERSION: string = '4.1.0'; +export const DEFAULT_NUGET_PATH_SUFFIX: string = 'NuGet/4.1.0/'; export const NUGET_EXE_TOOL_PATH_ENV_VAR: string = 'NuGetExeToolPath'; export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNuGetToPath?: boolean): Promise { if (toolLib.isExplicitVersion(versionSpec)) { // Check latest doesn't make sense when explicit version - checkLatest = false; + checkLatest = false; taskLib.debug('Exact match expected on version: ' + versionSpec); } else { @@ -65,7 +69,7 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu if (!versionInfo.url) { - taskLib.error(taskLib.loc("Error_NoUrlWasFoundWhichMatches", version)); + taskLib.error(taskLib.loc("Error_NoUrlWasFoundWhichMatches", version)); throw new Error(taskLib.loc("Error_NuGetToolInstallerFailer", NUGET_TOOL_NAME)); } @@ -94,12 +98,20 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu return fullNuGetPath; } -export async function cacheBundledNuGet_4_0_0() { - if (!toolLib.findLocalTool(NUGET_TOOL_NAME, NUGET_VERSION_4_0_0)) { - taskLib.debug('Placing bundled NuGet.exe 4.0.0 in tool lib cache'); - - let bundledNuGet4Location: string = getBundledNuGet_4_0_0_Location(); - toolLib.cacheFile(bundledNuGet4Location, NUGET_EXE_FILENAME, NUGET_TOOL_NAME, NUGET_VERSION_4_0_0); +export async function cacheBundledNuGet() { + let cachedVersionToUse = DEFAULT_NUGET_VERSION; + let nugetPathSuffix = DEFAULT_NUGET_PATH_SUFFIX; + if (taskLib.getVariable(FORCE_NUGET_4_0_0) && + taskLib.getVariable(FORCE_NUGET_4_0_0).toLowerCase() === "true"){ + cachedVersionToUse = NUGET_VERSION_4_0_0; + nugetPathSuffix = NUGET_VERSION_4_0_0_PATH_SUFFIX; + } + + if (!toolLib.findLocalTool(NUGET_TOOL_NAME, cachedVersionToUse)) { + taskLib.debug(`Placing bundled NuGet.exe ${cachedVersionToUse} in tool lib cache`); + + let bundledNuGet4Location: string = getBundledNuGet_Location([nugetPathSuffix]); + toolLib.cacheFile(bundledNuGet4Location, NUGET_EXE_FILENAME, NUGET_TOOL_NAME, cachedVersionToUse); } } @@ -115,10 +127,10 @@ function GetRestClientOptions(): restm.IRequestOptions async function getLatestMatchVersionInfo(versionSpec: string): Promise { taskLib.debug('Querying versions list'); - + let versionsUrl = 'https://dist.nuget.org/tools.json'; let rest: restm.RestClient = new restm.RestClient('vsts-tasks/NuGetToolInstaller'); - + let nugetVersions: INuGetVersionInfo[] = (await rest.get(versionsUrl, GetRestClientOptions())).result; // x.stage is the string representation of the enum, NuGetReleaseStage.Value = number, NuGetReleaseStage[NuGetReleaseStage.Value] = string, NuGetReleaseStage[x.stage] = number let releasedVersions: INuGetVersionInfo[] = nugetVersions.filter(x => x.stage.toString() !== NuGetReleaseStage[NuGetReleaseStage.EarlyAccessPreview]); @@ -127,7 +139,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise x.version).join("; "))); throw new Error(taskLib.loc("Error_NuGetToolInstallerFailer", NUGET_TOOL_NAME)); } @@ -136,10 +148,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise { try { nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR] || process.env[NUGET_EXE_CUSTOM_LOCATION]; if (!nuGetPath){ - nuGetGetter.cacheBundledNuGet_4_0_0(); - nuGetPath = await nuGetGetter.getNuGet("4.0.0"); + let cachedVersionToUse = nuGetGetter.DEFAULT_NUGET_VERSION; + nuGetGetter.cacheBundledNuGet(); + if (tl.getVariable(nuGetGetter.FORCE_NUGET_4_0_0) && + tl.getVariable(nuGetGetter.FORCE_NUGET_4_0_0).toLowerCase() === "true") { + cachedVersionToUse = nuGetGetter.NUGET_VERSION_4_0_0; + } + nuGetPath = await nuGetGetter.getNuGet(cachedVersionToUse); } } catch (error) { diff --git a/Tasks/NuGetCommand/package.json b/Tasks/NuGetCommand/package.json index 7424864bd70a..5466af3517ce 100644 --- a/Tasks/NuGetCommand/package.json +++ b/Tasks/NuGetCommand/package.json @@ -1,6 +1,6 @@ { "name": "nugetcommand", - "version": "2.0.13", + "version": "2.0.15", "description": "Restore, pack, or push NuGet packages, or run a NuGet command.", "main": "nugetcommandmain.js", "scripts": { diff --git a/Tasks/NuGetCommand/task.json b/Tasks/NuGetCommand/task.json index e66f19a4fab3..4c7284c3b7b9 100644 --- a/Tasks/NuGetCommand/task.json +++ b/Tasks/NuGetCommand/task.json @@ -9,7 +9,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 13 + "Patch": 15 }, "runsOn": [ "Agent", diff --git a/Tasks/NuGetCommand/task.loc.json b/Tasks/NuGetCommand/task.loc.json index 2c42e2f31a6a..6ebcd9188634 100644 --- a/Tasks/NuGetCommand/task.loc.json +++ b/Tasks/NuGetCommand/task.loc.json @@ -9,7 +9,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 13 + "Patch": 15 }, "runsOn": [ "Agent",