Skip to content

Commit cf6bf6f

Browse files
committed
allow for wrong-cased bundled nuget.exe
1 parent 0851c92 commit cf6bf6f

File tree

9 files changed

+38
-20
lines changed

9 files changed

+38
-20
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,24 @@ interface LocateOptions {
106106

107107
/** Array of filenames to use when searching for the tool. Defaults to the tool name. */
108108
toolFilenames?: string[];
109+
110+
/** Array of paths to search under. Defaults to agent NuGet locations */
111+
searchPath?: string[];
112+
113+
/** root that searchPaths are relative to. Defaults to the Agent.HomeDirectory build variable */
114+
root?: string;
109115
}
110116

111117
function locateTool(tool: string, opts?: LocateOptions) {
112-
let searchPath = ["externals/nuget", "agent/Worker/Tools/NuGetCredentialProvider", "agent/Worker/Tools"];
113-
let agentRoot = tl.getVariable("Agent.HomeDirectory");
118+
const defaultSearchPath = ["externals/nuget", "agent/Worker/Tools/NuGetCredentialProvider", "agent/Worker/Tools"];
119+
const defaultAgentRoot = tl.getVariable("Agent.HomeDirectory");
114120

115121
opts = opts || {};
116122
opts.toolFilenames = opts.toolFilenames || [tool];
117123

124+
let searchPath = opts.searchPath || defaultSearchPath;
125+
let agentRoot = opts.root || defaultAgentRoot;
126+
118127
tl.debug(`looking for tool ${tool}`);
119128

120129
for (let thisVariant of opts.toolFilenames) {
@@ -271,5 +280,24 @@ export function isCredentialConfigEnabled(quirks: NuGetQuirks): boolean {
271280
}
272281

273282
export function locateCredentialProvider(): string {
274-
return path.join(__dirname, 'NuGet/CredentialProvider');
283+
return path.join(__dirname, "NuGet/CredentialProvider");
275284
}
285+
286+
export function getBundledNuGetLocation(uxOption: string): string {
287+
let nuGetDir;
288+
if (uxOption === "3.5.0.1829") {
289+
nuGetDir = "NuGet/3.5.0";
290+
}
291+
else if (uxOption === "3.3.0") {
292+
nuGetDir = "NuGet/3.3.0";
293+
}
294+
else {
295+
throw new Error(tl.loc("NGCommon_UnabletoDetectNuGetVersion"));
296+
}
297+
298+
return locateTool("NuGet", {
299+
root: __dirname,
300+
searchPath: [nuGetDir],
301+
toolFilenames: ["NuGet.exe", "nuget.exe"],
302+
});
303+
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,4 @@ export function stripLeadingAndTrailingQuotes(path: string): string {
137137

138138
// substring returns a value *not* including the character at right
139139
return path.substring(left, right + 1);
140-
}
141-
142-
export function getBundledNuGetLocation(uxOption: string): string {
143-
if (uxOption === "3.5.0.1829"){
144-
return path.join(__dirname, 'NuGet/3.5.0/NuGet.exe')
145-
}
146-
else if (uxOption === "3.3.0"){
147-
return path.join(__dirname, 'NuGet/3.3.0/NuGet.exe');
148-
}
149-
throw new Error(tl.loc("NGCommon_UnabletoDetectNuGetVersion"));
150140
}

Tasks/NuGetInstaller/nugetinstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function main(): Promise<void> {
8989
throw new Error(tl.loc("NoNuGetSpecified"))
9090
}
9191
// Pull the pre-installed path for NuGet.
92-
nuGetPath = nutil.getBundledNuGetLocation(nugetUxOption);
92+
nuGetPath = ngToolRunner.getBundledNuGetLocation(nugetUxOption);
9393
}
9494

9595
let serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);

Tasks/NuGetInstaller/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 2,
12-
"Patch": 20
12+
"Patch": 23
1313
},
1414
"minimumAgentVersion": "1.83.0",
1515
"groups": [

Tasks/NuGetInstaller/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 2,
12-
"Patch": 20
12+
"Patch": 23
1313
},
1414
"minimumAgentVersion": "1.83.0",
1515
"groups": [

Tasks/NugetPublisher/nugetpublisher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function main(): Promise<void> {
8383
{
8484
throw new Error(tl.loc("NoNuGetSpecified"))
8585
}
86-
nuGetPath = nutil.getBundledNuGetLocation(nugetUxOption);
86+
nuGetPath = ngToolRunner.getBundledNuGetLocation(nugetUxOption);
8787
}
8888

8989
let serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);

Tasks/NugetPublisher/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 2,
12-
"Patch": 20
12+
"Patch": 23
1313
},
1414
"demands": [
1515
"Cmd"

Tasks/NugetPublisher/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 2,
12-
"Patch": 20
12+
"Patch": 23
1313
},
1414
"demands": [
1515
"Cmd"

definitions/nuget-task-common.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ declare module 'nuget-task-common/NuGetToolRunner' {
245245
export function isCredentialProviderEnabled(quirks: NuGetQuirks): boolean;
246246
export function isCredentialConfigEnabled(quirks: NuGetQuirks): boolean;
247247
export function locateCredentialProvider(): string;
248+
export function getBundledNuGetLocation(version: string): string;
248249

249250
}
250251
declare module 'nuget-task-common/INuGetCommandOptions' {
@@ -375,5 +376,4 @@ declare module 'nuget-task-common/Utility' {
375376
export function resolveFilterSpec(filterSpec: string, basePath?: string, allowEmptyMatch?: boolean): string[];
376377
export function resolveWildcardPath(pattern: string, allowEmptyWildcardMatch?: boolean): string[];
377378
export function stripLeadingAndTrailingQuotes(path: string): string;
378-
export function getBundledNuGetLocation(version: string): string;
379379
}

0 commit comments

Comments
 (0)