Skip to content

Commit 8b8975e

Browse files
author
Jiahong Wen
authored
Update NugetToolInstaller to add nuget script for unix system to get the correct version (#16397) (#16423)
* Add nuget script for non windows systems to pick up the correct version from bash task * update permissions to 500 * update version for common dependent tasks * add fs.exist to not overwrite file * bump pipAuth to patch 1 * move nuget string as const * bumping DownloadGitHubNugetPackageV1 version
1 parent 75b8e92 commit 8b8975e

File tree

26 files changed

+63
-29
lines changed

26 files changed

+63
-29
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as restm from 'typed-rest-client/RestClient';
44
import * as path from 'path';
55
import * as semver from 'semver';
66
import * as commandHelper from './CommandHelper';
7+
import * as fs from "fs";
8+
import * as os from "os";
9+
710
interface INuGetTools {
811
nugetexe: INuGetVersionInfo[]
912
}
@@ -23,6 +26,7 @@ enum NuGetReleaseStage
2326

2427
const NUGET_TOOL_NAME: string = 'NuGet';
2528
const NUGET_EXE_FILENAME: string = 'nuget.exe';
29+
const NUGET_SCRIPT_FILENAME: string = 'nuget';
2630

2731
export const FORCE_NUGET_4_0_0: string = 'FORCE_NUGET_4_0_0';
2832
export const NUGET_VERSION_4_0_0: string = '4.0.0';
@@ -96,9 +100,38 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
96100
let fullNuGetPath: string = path.join(toolPath, NUGET_EXE_FILENAME);
97101
taskLib.setVariable(NUGET_EXE_TOOL_PATH_ENV_VAR, fullNuGetPath);
98102

103+
// create a nuget posix script for nuget exe in non-windows agents
104+
if (os.platform() !== "win32") {
105+
generateNugetScript(toolPath, fullNuGetPath);
106+
}
107+
99108
return fullNuGetPath;
100109
}
101110

111+
function generateNugetScript(nugetToolPath: string, nugetExePath: string) {
112+
var nugetScriptPath = path.join(nugetToolPath, NUGET_SCRIPT_FILENAME);
113+
114+
if (fs.existsSync(nugetScriptPath)) {
115+
taskLib.debug(`nugetScriptPath already exist at ${nugetScriptPath}, skipped.`)
116+
} else {
117+
taskLib.debug(`create nugetScriptPath ${nugetScriptPath}`);
118+
119+
fs.writeFile(
120+
nugetScriptPath,
121+
`#!/bin/sh\nmono ${nugetExePath} "$@"\n`,
122+
(err) => {
123+
if (err) {
124+
taskLib.debug("Writing nuget script failed with error: " + err);
125+
} else {
126+
// give read and execute permissions to everyone
127+
fs.chmodSync(nugetScriptPath, "500");
128+
taskLib.debug("Writing nuget script succeeded");
129+
}
130+
}
131+
);
132+
}
133+
}
134+
102135
function pathExistsAsFile(path: string) {
103136
try {
104137
return taskLib.stats(path).isFile();

Tasks/DownloadGitHubNpmPackageV1/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 1,
12-
"Minor": 198,
13-
"Patch": 1
12+
"Minor": 204,
13+
"Patch": 0
1414
},
1515
"runsOn": [
1616
"Agent",

Tasks/DownloadGitHubNpmPackageV1/task.loc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 1,
12-
"Minor": 198,
13-
"Patch": 1
12+
"Minor": 204,
13+
"Patch": 0
1414
},
1515
"runsOn": [
1616
"Agent",

Tasks/DownloadGitHubNugetPackageV1/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"demands": [],
1818
"version": {
1919
"Major": 1,
20-
"Minor": 200,
21-
"Patch": 1
20+
"Minor": 204,
21+
"Patch": 0
2222
},
2323
"minimumAgentVersion": "2.115.0",
2424
"instanceNameFormat": "dotnet restore",

Tasks/DownloadGitHubNugetPackageV1/task.loc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"demands": [],
1818
"version": {
1919
"Major": 1,
20-
"Minor": 200,
21-
"Patch": 1
20+
"Minor": 204,
21+
"Patch": 0
2222
},
2323
"minimumAgentVersion": "2.115.0",
2424
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",

Tasks/NpmAuthenticateV0/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 202,
12+
"Minor": 204,
1313
"Patch": 0
1414
},
1515
"runsOn": [

Tasks/NpmAuthenticateV0/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 202,
12+
"Minor": 204,
1313
"Patch": 0
1414
},
1515
"runsOn": [

Tasks/NuGetCommandV2/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 2,
12-
"Minor": 202,
12+
"Minor": 204,
1313
"Patch": 0
1414
},
1515
"runsOn": [

Tasks/NuGetCommandV2/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 2,
12-
"Minor": 202,
12+
"Minor": 204,
1313
"Patch": 0
1414
},
1515
"runsOn": [

Tasks/NuGetInstallerV0/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 202,
12+
"Minor": 204,
1313
"Patch": 0
1414
},
1515
"runsOn": [

0 commit comments

Comments
 (0)