Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NugetToolInstaller to add nuget script for unix system to get the correct version #16397

Merged
27 changes: 27 additions & 0 deletions Tasks/Common/packaging-common/nuget/NuGetToolGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import * as restm from 'typed-rest-client/RestClient';
import * as path from 'path';
import * as semver from 'semver';
import * as commandHelper from './CommandHelper';
import * as fs from "fs";
import * as os from "os";

interface INuGetTools {
nugetexe: INuGetVersionInfo[]
}
Expand Down Expand Up @@ -96,9 +99,33 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
let fullNuGetPath: string = path.join(toolPath, NUGET_EXE_FILENAME);
taskLib.setVariable(NUGET_EXE_TOOL_PATH_ENV_VAR, fullNuGetPath);

// create a nuget posix script for nuget exe in non-windows agents
if (os.platform() !== "win32") {
jiaw37 marked this conversation as resolved.
Show resolved Hide resolved
generateNugetScript(toolPath, fullNuGetPath);
}

return fullNuGetPath;
}

function generateNugetScript(nugetToolPath: string, nugetExePath: string) {
var nugetScriptPath = path.join(nugetToolPath, "nuget");
taskLib.debug(`create nugetScriptPath ${nugetScriptPath}`);

fs.writeFile(
jiaw37 marked this conversation as resolved.
Show resolved Hide resolved
nugetScriptPath,
`#!/bin/sh\nmono ${nugetExePath} "$@"\n`,
(err) => {
if (err) {
taskLib.debug("Writing nuget script failed with error: " + err);
} else {
// give read and execute permissions to everyone
fs.chmodSync(nugetScriptPath, "555");
jiaw37 marked this conversation as resolved.
Show resolved Hide resolved
taskLib.debug("Writing nuget script succeeded");
}
}
);
}

function pathExistsAsFile(path: string) {
try {
return taskLib.stats(path).isFile();
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 202,
"Minor": 206,
"Patch": 0
},
"preview": false,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 202,
"Minor": 206,
"Patch": 0
},
"preview": false,
Expand Down