Skip to content

Commit e0c8b42

Browse files
authored
Update default NuGet to 4.1.0 (#5805)
1 parent c798166 commit e0c8b42

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

Tasks/Common/nuget-task-common/NuGetToolGetter.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ enum NuGetReleaseStage
2222

2323
const NUGET_TOOL_NAME: string = 'NuGet';
2424
const NUGET_EXE_FILENAME: string = 'nuget.exe';
25-
const NUGET_VERSION_4_0_0: string = '4.0.0';
2625

26+
export const FORCE_NUGET_4_0_0: string = 'FORCE_NUGET_4_0_0';
27+
export const NUGET_VERSION_4_0_0: string = '4.0.0';
28+
export const NUGET_VERSION_4_0_0_PATH_SUFFIX: string = 'NuGet/4.0.0/';
29+
export const DEFAULT_NUGET_VERSION: string = '4.1.0';
30+
export const DEFAULT_NUGET_PATH_SUFFIX: string = 'NuGet/4.1.0/';
2731
export const NUGET_EXE_TOOL_PATH_ENV_VAR: string = 'NuGetExeToolPath';
2832

2933
export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNuGetToPath?: boolean): Promise<string> {
3034
if (toolLib.isExplicitVersion(versionSpec)) {
3135
// Check latest doesn't make sense when explicit version
32-
checkLatest = false;
36+
checkLatest = false;
3337
taskLib.debug('Exact match expected on version: ' + versionSpec);
3438
}
3539
else {
@@ -65,7 +69,7 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
6569

6670
if (!versionInfo.url)
6771
{
68-
taskLib.error(taskLib.loc("Error_NoUrlWasFoundWhichMatches", version));
72+
taskLib.error(taskLib.loc("Error_NoUrlWasFoundWhichMatches", version));
6973
throw new Error(taskLib.loc("Error_NuGetToolInstallerFailer", NUGET_TOOL_NAME));
7074
}
7175

@@ -94,12 +98,20 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
9498
return fullNuGetPath;
9599
}
96100

97-
export async function cacheBundledNuGet_4_0_0() {
98-
if (!toolLib.findLocalTool(NUGET_TOOL_NAME, NUGET_VERSION_4_0_0)) {
99-
taskLib.debug('Placing bundled NuGet.exe 4.0.0 in tool lib cache');
100-
101-
let bundledNuGet4Location: string = getBundledNuGet_4_0_0_Location();
102-
toolLib.cacheFile(bundledNuGet4Location, NUGET_EXE_FILENAME, NUGET_TOOL_NAME, NUGET_VERSION_4_0_0);
101+
export async function cacheBundledNuGet() {
102+
let cachedVersionToUse = DEFAULT_NUGET_VERSION;
103+
let nugetPathSuffix = DEFAULT_NUGET_PATH_SUFFIX;
104+
if (taskLib.getVariable(FORCE_NUGET_4_0_0) &&
105+
taskLib.getVariable(FORCE_NUGET_4_0_0).toLowerCase() === "true"){
106+
cachedVersionToUse = NUGET_VERSION_4_0_0;
107+
nugetPathSuffix = NUGET_VERSION_4_0_0_PATH_SUFFIX;
108+
}
109+
110+
if (!toolLib.findLocalTool(NUGET_TOOL_NAME, cachedVersionToUse)) {
111+
taskLib.debug(`Placing bundled NuGet.exe ${cachedVersionToUse} in tool lib cache`);
112+
113+
let bundledNuGet4Location: string = getBundledNuGet_Location([nugetPathSuffix]);
114+
toolLib.cacheFile(bundledNuGet4Location, NUGET_EXE_FILENAME, NUGET_TOOL_NAME, cachedVersionToUse);
103115
}
104116
}
105117

@@ -115,10 +127,10 @@ function GetRestClientOptions(): restm.IRequestOptions
115127

116128
async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVersionInfo> {
117129
taskLib.debug('Querying versions list');
118-
130+
119131
let versionsUrl = 'https://dist.nuget.org/tools.json';
120132
let rest: restm.RestClient = new restm.RestClient('vsts-tasks/NuGetToolInstaller');
121-
133+
122134
let nugetVersions: INuGetVersionInfo[] = (await rest.get<INuGetVersionInfo[]>(versionsUrl, GetRestClientOptions())).result;
123135
// x.stage is the string representation of the enum, NuGetReleaseStage.Value = number, NuGetReleaseStage[NuGetReleaseStage.Value] = string, NuGetReleaseStage[x.stage] = number
124136
let releasedVersions: INuGetVersionInfo[] = nugetVersions.filter(x => x.stage.toString() !== NuGetReleaseStage[NuGetReleaseStage.EarlyAccessPreview]);
@@ -127,7 +139,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
127139
let version: string = toolLib.evaluateVersions(versionStringsFromDist, versionSpec);
128140
if (!version)
129141
{
130-
taskLib.error(taskLib.loc("Error_NoVersionWasFoundWhichMatches", versionSpec));
142+
taskLib.error(taskLib.loc("Error_NoVersionWasFoundWhichMatches", versionSpec));
131143
taskLib.error(taskLib.loc("Info_AvailableVersions", releasedVersions.map(x => x.version).join("; ")));
132144
throw new Error(taskLib.loc("Error_NuGetToolInstallerFailer", NUGET_TOOL_NAME));
133145
}
@@ -136,10 +148,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
136148
}
137149

138150

139-
140-
function getBundledNuGet_4_0_0_Location(): string {
141-
const nugetPaths: string[] = ['NuGet/4.0.0/'];
142-
151+
function getBundledNuGet_Location(nugetPaths: string[]): string {
143152
let taskNodeModulesPath: string = path.dirname(__dirname);
144153
let taskRootPath: string = path.dirname(taskNodeModulesPath);
145154
const toolPath = commandHelper.locateTool("NuGet",

Tasks/NuGetCommand/Tests/NugetMockHelper.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import * as nugetPackUtils from "nuget-task-common/PackUtilities"
77
export class NugetMockHelper {
88
private defaultNugetVersion = '4.0.0';
99
private defaultNugetVersionInfo = [4,0,0,0];
10-
10+
1111
constructor(
12-
private tmr: tmrm.TaskMockRunner) {
12+
private tmr: tmrm.TaskMockRunner) {
1313
process.env['AGENT_HOMEDIRECTORY'] = "c:\\agent\\home\\directory";
1414
process.env['BUILD_SOURCESDIRECTORY'] = "c:\\agent\\home\\directory\\sources",
1515
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"parameters\":{\"AccessToken\":\"token\"},\"scheme\":\"OAuth\"}";
1616
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
1717
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "c:\\agent\\home\\directory";
1818
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";
1919
}
20-
20+
2121
public setNugetVersionInputDefault() {
2222
}
23-
23+
2424
public registerDefaultNugetVersionMock() {
2525
this.registerNugetVersionMock(this.defaultNugetVersion, this.defaultNugetVersionInfo);
2626
this.registerNugetToolGetterMock();
@@ -31,11 +31,16 @@ export class NugetMockHelper {
3131
getNuGet: function(versionSpec) {
3232
return "c:\\from\\tool\\installer\\nuget.exe";
3333
},
34-
cacheBundledNuGet_4_0_0: function()
35-
{}
34+
cacheBundledNuGet: function(){},
35+
FORCE_NUGET_4_0_0: 'FORCE_NUGET_4_0_0',
36+
NUGET_VERSION_4_0_0: '4.0.0',
37+
NUGET_VERSION_4_0_0_PATH_SUFFIX: 'NuGet/4.0.0/',
38+
DEFAULT_NUGET_VERSION: '4.1.0',
39+
DEFAULT_NUGET_PATH_SUFFIX: 'NuGet/4.1.0/',
40+
NUGET_EXE_TOOL_PATH_ENV_VAR: "NuGetExeToolPath"
3641
} )
3742
}
38-
43+
3944
public registerNugetVersionMock(productVersion: string, versionInfoVersion: number[]) {
4045
this.registerNugetVersionMockInternal(productVersion, versionInfoVersion);
4146
this.registerMockWithMultiplePaths(['nuget-task-common/pe-parser', './pe-parser'], {
@@ -59,7 +64,7 @@ export class NugetMockHelper {
5964
}
6065
})
6166
}
62-
67+
6368
public registerNugetUtilityMock(projectFile: string[]) {
6469
this.tmr.registerMock('nuget-task-common/Utility', {
6570
getPatternsArrayFromInput: function(input) {
@@ -138,13 +143,13 @@ export class NugetMockHelper {
138143
this.tmr.registerMock('vso-node-api/WebApi', {
139144
getBearerHandler: function(token){
140145
return {};
141-
},
146+
},
142147
WebApi: function(url, handler){
143148
return {
144149
getCoreApi: function() {
145-
return {
150+
return {
146151
vsoClient: {
147-
getVersioningData: async function (ApiVersion, PackagingAreaName, PackageAreaId, Obj) {
152+
getVersioningData: async function (ApiVersion, PackagingAreaName, PackageAreaId, Obj) {
148153
return { requestUrl:"foobar" }
149154
}
150155
}
@@ -154,7 +159,7 @@ export class NugetMockHelper {
154159
}
155160
})
156161
}
157-
162+
158163
public setAnswers(a) {
159164
a.osType["osType"] = "Windows_NT";
160165
a.exist["c:\\agent\\home\\directory\\externals\\nuget\\nuget.exe"] = true;

Tasks/NuGetCommand/make.json

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
{
2424
"url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/4.0.0.2283/NuGet.zip",
2525
"dest": "./NuGet/4.0.0/"
26+
},
27+
{
28+
"url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/4.1.0/NuGet.zip",
29+
"dest": "./NuGet/4.1.0/"
2630
}
2731
]
2832
}

Tasks/NuGetCommand/nugetcommandmain.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ async function main(): Promise<void> {
1818
try {
1919
nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR] || process.env[NUGET_EXE_CUSTOM_LOCATION];
2020
if (!nuGetPath){
21-
nuGetGetter.cacheBundledNuGet_4_0_0();
22-
nuGetPath = await nuGetGetter.getNuGet("4.0.0");
21+
let cachedVersionToUse = nuGetGetter.DEFAULT_NUGET_VERSION;
22+
nuGetGetter.cacheBundledNuGet();
23+
if (tl.getVariable(nuGetGetter.FORCE_NUGET_4_0_0) &&
24+
tl.getVariable(nuGetGetter.FORCE_NUGET_4_0_0).toLowerCase() === "true") {
25+
cachedVersionToUse = nuGetGetter.NUGET_VERSION_4_0_0;
26+
}
27+
nuGetPath = await nuGetGetter.getNuGet(cachedVersionToUse);
2328
}
2429
}
2530
catch (error) {

Tasks/NuGetCommand/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nugetcommand",
3-
"version": "2.0.13",
3+
"version": "2.0.15",
44
"description": "Restore, pack, or push NuGet packages, or run a NuGet command.",
55
"main": "nugetcommandmain.js",
66
"scripts": {

Tasks/NuGetCommand/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 2,
1111
"Minor": 0,
12-
"Patch": 13
12+
"Patch": 15
1313
},
1414
"runsOn": [
1515
"Agent",

Tasks/NuGetCommand/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 2,
1111
"Minor": 0,
12-
"Patch": 13
12+
"Patch": 15
1313
},
1414
"runsOn": [
1515
"Agent",

0 commit comments

Comments
 (0)