diff --git a/Tasks/NuGetCommand/Common/INuGetCommandOptions.ts b/Tasks/NuGetCommand/Common/INuGetCommandOptions.ts index 3b313c95d904..e65c84310126 100644 --- a/Tasks/NuGetCommand/Common/INuGetCommandOptions.ts +++ b/Tasks/NuGetCommand/Common/INuGetCommandOptions.ts @@ -1,4 +1,4 @@ -import {NuGetEnvironmentSettings} from "./NuGetToolRunner"; +import { NuGetEnvironmentSettings } from "./NuGetToolRunner"; export interface INuGetCommandOptions { /** settings used to initialize the environment NuGet.exe is invoked in */ diff --git a/Tasks/NuGetCommand/Common/NuGetConfigHelper.ts b/Tasks/NuGetCommand/Common/NuGetConfigHelper.ts index c5b6426174dd..db6896e5816e 100644 --- a/Tasks/NuGetCommand/Common/NuGetConfigHelper.ts +++ b/Tasks/NuGetCommand/Common/NuGetConfigHelper.ts @@ -30,23 +30,24 @@ export class NuGetConfigHelper { public ensureTempConfigCreated() { // save nuget config file to agent build directory - console.log("save nuget.config to temp config file"); - if (!(fs.existsSync(this.tempNugetConfigDir))) { - fs.mkdirSync(this.tempNugetConfigDir); + console.log(tl.loc("Info_SavingTempConfig")); + + if (!tl.exist(this.tempNugetConfigDir)) { + tl.mkdirP(this.tempNugetConfigDir); } this.tempNugetConfigPath = path.join(this.tempNugetConfigDir, this.tempNugetConfigFileName); - if (!fs.existsSync(this.tempNugetConfigPath)) + if (!tl.exist(this.tempNugetConfigPath)) { if (this.nugetConfigPath) { // don't use cp as that copies the read-only flag, and tfvc sets that on files let content = fs.readFileSync(this.nugetConfigPath); - fs.writeFileSync(this.tempNugetConfigPath, content); + tl.writeFile(this.tempNugetConfigPath, content); } else { // small file, use writeFileSync - fs.writeFileSync(this.tempNugetConfigPath, ""); + tl.writeFile(this.tempNugetConfigPath, ""); } } } diff --git a/Tasks/NuGetCommand/Common/NuGetToolRunner.ts b/Tasks/NuGetCommand/Common/NuGetToolRunner.ts index 23388894b2bd..787aac91f894 100644 --- a/Tasks/NuGetCommand/Common/NuGetToolRunner.ts +++ b/Tasks/NuGetCommand/Common/NuGetToolRunner.ts @@ -143,7 +143,7 @@ export async function getNuGetQuirksAsync(nuGetExePath: string): Promise { }); @@ -240,7 +240,7 @@ describe('NuGetRestore Suite', function () { tr.run() assert(tr.invokedToolCount == 1, 'should have run NuGet once'); - assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory C:\\out\\dir -version x.y.z-CI-YYYYMMDD-HHMMSS'), 'it should have run NuGet'); + assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory c:\\agent\\home\\directory -Properties -version x.y.z-CI-YYYYMMDD-HHMMSS'), 'it should have run NuGet'); assert(tr.stdOutContained('setting console code page'), 'it should have run chcp'); assert(tr.stdOutContained('NuGet output here'), "should have nuget output"); assert(tr.succeeded, 'should have succeeded'); @@ -256,7 +256,7 @@ describe('NuGetRestore Suite', function () { tr.run() assert(tr.invokedToolCount == 1, 'should have run NuGet once'); - assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory C:\\out\\dir -version XX.YY.ZZ'), 'it should have run NuGet'); + assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory c:\\agent\\home\\directory -Properties -version XX.YY.ZZ'), 'it should have run NuGet'); assert(tr.stdOutContained('setting console code page'), 'it should have run chcp'); assert(tr.stdOutContained('NuGet output here'), "should have nuget output"); assert(tr.succeeded, 'should have succeeded'); @@ -272,7 +272,7 @@ describe('NuGetRestore Suite', function () { tr.run() assert(tr.invokedToolCount == 1, 'should have run NuGet once'); - assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory C:\\out\\dir -version 1.2.3'), 'it should have run NuGet'); + assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory c:\\agent\\home\\directory -Properties -version 1.2.3'), 'it should have run NuGet'); assert(tr.stdOutContained('setting console code page'), 'it should have run chcp'); assert(tr.stdOutContained('NuGet output here'), "should have nuget output"); assert(tr.succeeded, 'should have succeeded'); diff --git a/Tasks/NuGetCommand/Tests/PackTests/packBuildNumber.ts b/Tasks/NuGetCommand/Tests/PackTests/packBuildNumber.ts index e515a5ffa328..f24a94e15eee 100644 --- a/Tasks/NuGetCommand/Tests/PackTests/packBuildNumber.ts +++ b/Tasks/NuGetCommand/Tests/PackTests/packBuildNumber.ts @@ -21,7 +21,7 @@ let a: ma.TaskLibAnswers = { }, "which": {}, "exec": { - "c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory C:\\out\\dir -version 1.2.3": { + "c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory c:\\agent\\home\\directory -Properties -version 1.2.3": { "code": 0, "stdout": "NuGet output here", "stderr": "" @@ -34,6 +34,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nuspec": { "isFile": true } + }, + "findMatch": { + "foo.nuspec" : ["c:\\agent\\home\\directory\\foo.nuspec"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/PackTests/packEnvVar.ts b/Tasks/NuGetCommand/Tests/PackTests/packEnvVar.ts index 1a8106e4854a..b187598a2aec 100644 --- a/Tasks/NuGetCommand/Tests/PackTests/packEnvVar.ts +++ b/Tasks/NuGetCommand/Tests/PackTests/packEnvVar.ts @@ -22,7 +22,7 @@ let a: ma.TaskLibAnswers = { }, "which": {}, "exec": { - "c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory C:\\out\\dir -version XX.YY.ZZ": { + "c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory c:\\agent\\home\\directory -Properties -version XX.YY.ZZ": { "code": 0, "stdout": "NuGet output here", "stderr": "" @@ -35,6 +35,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nuspec": { "isFile": true } + }, + "findMatch": { + "foo.nuspec" : ["c:\\agent\\home\\directory\\foo.nuspec"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/PackTests/packPrerelease.ts b/Tasks/NuGetCommand/Tests/PackTests/packPrerelease.ts index 8e0f4595a95d..1e02b0875a39 100644 --- a/Tasks/NuGetCommand/Tests/PackTests/packPrerelease.ts +++ b/Tasks/NuGetCommand/Tests/PackTests/packPrerelease.ts @@ -24,7 +24,7 @@ let a: ma.TaskLibAnswers = { }, "which": {}, "exec": { - "c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory C:\\out\\dir -version x.y.z-CI-YYYYMMDD-HHMMSS": { + "c:\\from\\tool\\installer\\nuget.exe pack c:\\agent\\home\\directory\\foo.nuspec -NonInteractive -OutputDirectory c:\\agent\\home\\directory -Properties -version x.y.z-CI-YYYYMMDD-HHMMSS": { "code": 0, "stdout": "NuGet output here", "stderr": "" @@ -37,6 +37,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nuspec": { "isFile": true } + }, + "findMatch": { + "foo.nuspec" : ["c:\\agent\\home\\directory\\foo.nuspec"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/PublishTests/externalFeedNuGet.ts b/Tasks/NuGetCommand/Tests/PublishTests/externalFeedNuGet.ts index ed9375f652ee..a3953918cfc9 100644 --- a/Tasks/NuGetCommand/Tests/PublishTests/externalFeedNuGet.ts +++ b/Tasks/NuGetCommand/Tests/PublishTests/externalFeedNuGet.ts @@ -9,7 +9,7 @@ let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr); nmh.setNugetVersionInputDefault(); tmr.setInput('command', 'push'); -tmr.setInput('searchPattern', 'foo.nupkg'); +tmr.setInput('searchPatternPush', 'foo.nupkg'); tmr.setInput('nuGetFeedType', 'external'); tmr.setInput('connectedServiceName', 'externalNuGetFeed'); @@ -31,6 +31,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nupkg": { "isFile": true } + }, + "findMatch": { + "foo.nupkg" : ["c:\\agent\\home\\directory\\foo.nupkg"] } }; nmh.setAnswers(a); @@ -41,6 +44,5 @@ nmh.registerDefaultNugetVersionMock(); nmh.registerToolRunnerMock(); nmh.registerNugetConfigMock(); nmh.RegisterLocationServiceMocks(); -//nmh.registerCommonUtilities(); tmr.run(); diff --git a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedNuGet.ts b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedNuGet.ts index cf1795aaa684..45bd1c961588 100644 --- a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedNuGet.ts +++ b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedNuGet.ts @@ -9,7 +9,7 @@ let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr); nmh.setNugetVersionInputDefault(); tmr.setInput('command', 'push'); -tmr.setInput('searchPattern', 'foo.nupkg'); +tmr.setInput('searchPatternPush', 'foo.nupkg'); tmr.setInput('nuGetFeedType', 'internal'); tmr.setInput('feedPublish', 'FeedFooId'); tmr.setInput('allowPackageConflicts', 'false'); @@ -32,6 +32,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nupkg": { "isFile": true } + }, + "findMatch": { + "foo.nupkg" : ["c:\\agent\\home\\directory\\foo.nupkg"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPush.ts b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPush.ts index 3f769e606d02..b88570451e9c 100644 --- a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPush.ts +++ b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPush.ts @@ -9,7 +9,7 @@ let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr); nmh.setNugetVersionInputDefault(); tmr.setInput('command', 'push'); -tmr.setInput('searchPattern', 'foo.nupkg'); +tmr.setInput('searchPatternPush', 'foo.nupkg'); tmr.setInput('nuGetFeedType', 'internal'); tmr.setInput('feedPublish', 'FeedFooId'); tmr.setInput('allowPackageConflicts', 'false'); @@ -32,6 +32,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nupkg": { "isFile": true } + }, + "findMatch": { + "foo.nupkg" : ["c:\\agent\\home\\directory\\foo.nupkg"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushAllowConflict.ts b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushAllowConflict.ts index aabd2ef6fd1e..51d6b0bb2300 100644 --- a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushAllowConflict.ts +++ b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushAllowConflict.ts @@ -9,7 +9,7 @@ let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr); nmh.setNugetVersionInputDefault(); tmr.setInput('command', 'push'); -tmr.setInput('searchPattern', 'foo.nupkg'); +tmr.setInput('searchPatternPush', 'foo.nupkg'); tmr.setInput('nuGetFeedType', 'internal'); tmr.setInput('feedPublish', 'FeedFooId'); tmr.setInput('allowPackageConflicts', 'true'); @@ -32,6 +32,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nupkg": { "isFile": true } + }, + "findMatch": { + "foo.nupkg" : ["c:\\agent\\home\\directory\\foo.nupkg"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushDisallowConflict.ts b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushDisallowConflict.ts index d1842926180b..910d2e421a6e 100644 --- a/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushDisallowConflict.ts +++ b/Tasks/NuGetCommand/Tests/PublishTests/internalFeedVstsNuGetPushDisallowConflict.ts @@ -9,7 +9,7 @@ let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr); nmh.setNugetVersionInputDefault(); tmr.setInput('command', 'push'); -tmr.setInput('searchPattern', 'foo.nupkg'); +tmr.setInput('searchPatternPush', 'foo.nupkg'); tmr.setInput('nuGetFeedType', 'internal'); tmr.setInput('feedPublish', 'FeedFooId'); tmr.setInput('allowPackageConflicts', 'false'); @@ -32,6 +32,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\foo.nupkg": { "isFile": true } + }, + "findMatch": { + "foo.nupkg" : ["c:\\agent\\home\\directory\\foo.nupkg"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/multiplesln.ts b/Tasks/NuGetCommand/Tests/RestoreTests/multiplesln.ts index fa2e99ed8a36..b8320ee25a12 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/multiplesln.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/multiplesln.ts @@ -38,7 +38,10 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\double\\double.sln": { "isFile": true } - } + }, + "findMatch": { + "**//*.sln" : ["c:\\agent\\home\\directory\\single.sln", "c:\\agent\\home\\directory\\double\\double.sln"] + } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/pkgconfig.ts b/Tasks/NuGetCommand/Tests/RestoreTests/pkgconfig.ts index 7bbe8aa91ad3..57c02840c70d 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/pkgconfig.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/pkgconfig.ts @@ -30,6 +30,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\packages.config": { "isFile": true } + }, + "findMatch": { + "packages.config" : ["c:\\agent\\home\\directory\\packages.config"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceMultiple.ts b/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceMultiple.ts index 9bbda7191deb..67ecbbc8f645 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceMultiple.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceMultiple.ts @@ -35,6 +35,9 @@ let a: ma.TaskLibAnswers = { }, "rmRF": { "c:\\agent\\home\\directory\\tempNuGet_.config": { success: true } + }, + "findMatch": { + "packages.config" : ["c:\\agent\\home\\directory\\packages.config"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceNuGetOrg.ts b/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceNuGetOrg.ts index 641887c26b7f..b8b54840dd68 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceNuGetOrg.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceNuGetOrg.ts @@ -34,6 +34,9 @@ let a: ma.TaskLibAnswers = { }, "rmRF": { "c:\\agent\\home\\directory\\tempNuGet_.config": { success: true } + }, + "findMatch": { + "packages.config" : ["c:\\agent\\home\\directory\\packages.config"] } }; diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceVsts.ts b/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceVsts.ts index 5caa94da02f4..ea51df146498 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceVsts.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/selectSourceVsts.ts @@ -36,6 +36,9 @@ let a: ma.TaskLibAnswers = { }, "rmRF": { "c:\\agent\\home\\directory\\tempNuGet_.config": { success: true } + }, + "findMatch": { + "packages.config" : ["c:\\agent\\home\\directory\\packages.config"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/singlesln.ts b/Tasks/NuGetCommand/Tests/RestoreTests/singlesln.ts index a86072a82e95..169797c5fb34 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/singlesln.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/singlesln.ts @@ -30,6 +30,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\single.sln": { "isFile": true } + }, + "findMatch": { + "single.sln" : ["c:\\agent\\home\\directory\\single.sln"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnConfigFile.ts b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnConfigFile.ts index 4b6028decdfb..b8f061ade75d 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnConfigFile.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnConfigFile.ts @@ -37,6 +37,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\tempNuGet_.config": { "success": true } + }, + "findMatch": { + "single.sln" : ["c:\\agent\\home\\directory\\single.sln"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnCredentialProvider.ts b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnCredentialProvider.ts index e84c76ff6c61..10c074712830 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnCredentialProvider.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnCredentialProvider.ts @@ -30,6 +30,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\single.sln": { "isFile": true } + }, + "findMatch": { + "single.sln" : ["c:\\agent\\home\\directory\\single.sln"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnMono.ts b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnMono.ts index 7f5b7535b7c3..48f6e96bf8d0 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnMono.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnMono.ts @@ -38,6 +38,9 @@ let a: ma.TaskLibAnswers = { "~/myagent/_work/1/s/single.sln": { "isFile": true } + }, + "findMatch": { + "single.sln" : ["~/myagent/_work/1/s/single.sln"] } }; tmr.setAnswers(a); diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnNoCache.ts b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnNoCache.ts index a6f7dadd3f3e..2cc27fce3bf6 100644 --- a/Tasks/NuGetCommand/Tests/RestoreTests/singleslnNoCache.ts +++ b/Tasks/NuGetCommand/Tests/RestoreTests/singleslnNoCache.ts @@ -31,6 +31,9 @@ let a: ma.TaskLibAnswers = { "c:\\agent\\home\\directory\\single.sln": { "isFile": true } + }, + "findMatch": { + "single.sln" : ["c:\\agent\\home\\directory\\single.sln"] } }; nmh.setAnswers(a); diff --git a/Tasks/NuGetCommand/make.json b/Tasks/NuGetCommand/make.json index 3d3924d64f07..ba90dc8a461a 100644 --- a/Tasks/NuGetCommand/make.json +++ b/Tasks/NuGetCommand/make.json @@ -13,13 +13,5 @@ ], "options": "-Rf" } - ], - "externals": { - "archivePackages": [ - { - "url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/4.0.0.2283/NuGet.zip", - "dest": "./VstsNuGetPush/0.13.0/" - } - ] - } + ] } \ No newline at end of file diff --git a/Tasks/NuGetCommand/nugetcommandmain.ts b/Tasks/NuGetCommand/nugetcommandmain.ts index cc80b70fb3f4..f94036e59ae5 100644 --- a/Tasks/NuGetCommand/nugetcommandmain.ts +++ b/Tasks/NuGetCommand/nugetcommandmain.ts @@ -5,23 +5,41 @@ import * as nugetRestore from './nugetrestore'; import * as nugetPublish from './nugetpublisher'; import * as nugetPack from './nugetpack'; import * as nugetCustom from './nugetcustom'; +import nuGetGetter = require("nuget-task-common/NuGetToolGetter"); async function main(): Promise { tl.setResourcePath(path.join(__dirname, "task.json")); + // Getting NuGet + tl.debug('Getting NuGet'); + let nuGetPath: string = undefined; + try { + nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR]; + if (!nuGetPath){ + nuGetPath = await nuGetGetter.getNuGet("4.0.0"); + } + } + catch (error) { + tl.setResult(tl.TaskResult.Failed, error.message); + return; + } + let nugetCommand = tl.getInput("command", true); switch(nugetCommand) { case "restore": - nugetRestore.run(); + nugetRestore.run(nuGetPath); break; case "pack": - nugetPack.run(); + nugetPack.run(nuGetPath); break; case "push": - nugetPublish.run(); + nugetPublish.run(nuGetPath); break; case "custom": - nugetCustom.run(); + nugetCustom.run(nuGetPath); + break; + default: + tl.setResult(tl.TaskResult.Failed, tl.loc("Error_CommandNotRecognized", nugetCommand)); break; } } diff --git a/Tasks/NuGetCommand/nugetcustom.ts b/Tasks/NuGetCommand/nugetcustom.ts index ec80df5bec9d..64b25c1139e9 100644 --- a/Tasks/NuGetCommand/nugetcustom.ts +++ b/Tasks/NuGetCommand/nugetcustom.ts @@ -1,6 +1,4 @@ import * as tl from "vsts-task-lib/task"; -// Remove once task lib 2.0.4 releases -global['_vsts_task_lib_loaded'] = true; import * as ngToolRunner from "./Common/NuGetToolRunner"; import * as nutil from "nuget-task-common/Utility"; import * as path from "path"; @@ -19,7 +17,7 @@ class NuGetExecutionOptions { ) { } } -export async function run(): Promise { +export async function run(nuGetPath: string): Promise { nutil.setConsoleCodePage(); tl.setResourcePath(path.join(__dirname, "task.json")); @@ -29,20 +27,6 @@ export async function run(): Promise { let args: string = tl.getInput("arguments", false); - // Getting NuGet - tl.debug('Getting NuGet'); - let nuGetPath: string = undefined; - try { - nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR]; - if (!nuGetPath){ - nuGetPath = await nuGetGetter.getNuGet("4.0.0"); - } - } - catch (error) { - tl.setResult(tl.TaskResult.Failed, error.message); - return; - } - const version = await peParser.getFileVersionInfoAsync(nuGetPath); if(version.productVersion.a < 3 || (version.productVersion.a <= 3 && version.productVersion.b < 5)) { diff --git a/Tasks/NuGetCommand/nugetpack.ts b/Tasks/NuGetCommand/nugetpack.ts index dcebd56a23a9..921987943eea 100644 --- a/Tasks/NuGetCommand/nugetpack.ts +++ b/Tasks/NuGetCommand/nugetpack.ts @@ -1,6 +1,4 @@ import * as tl from "vsts-task-lib/task"; -// Remove once task lib 2.0.4 releases -global['_vsts_task_lib_loaded'] = true; import * as nutil from "nuget-task-common/Utility"; import nuGetGetter = require("nuget-task-common/NuGetToolGetter"); import * as path from "path"; @@ -21,12 +19,11 @@ class PackOptions implements INuGetCommandOptions { ) { } } -export async function run(): Promise { +export async function run(nuGetPath: string): Promise { nutil.setConsoleCodePage(); let searchPattern = tl.getPathInput("searchPatternPack", true); let configuration = tl.getInput("configurationToPack"); - let outputDir = tl.getPathInput("outputDir"); let versioningScheme = tl.getInput("versioningScheme"); let includeRefProj = tl.getBoolInput("includeReferencedProjects"); let versionEnvVar = tl.getInput("versionEnvVar"); @@ -35,6 +32,19 @@ export async function run(): Promise { let patchVersion = tl.getInput("requestedPatchVersion"); let propertiesInput = tl.getInput("buildProperties"); let verbosity = tl.getInput("verbosityPack"); + let outputDir = undefined; + + try + { + // If outputDir is not provided then the root working directory is set by default. + // By requiring it, it will throw an error if it is not provided and we can set it to undefined. + outputDir = tl.getPathInput("outputDir", true); + } + catch(error) + { + outputDir = undefined; + } + try{ if(versioningScheme !== "off" && includeRefProj) { @@ -97,27 +107,23 @@ export async function run(): Promise { tl.debug(`Creating output directory: ${outputDir}`); tl.mkdirP(outputDir); } - - let filesList = nutil.resolveFilterSpec(searchPattern); + + let useLegacyFind: boolean = tl.getVariable("NuGet.UseLegacyFindFiles") === "true"; + let filesList: string[] = []; + if (!useLegacyFind) { + let findOptions: tl.FindOptions = {}; + let matchOptions: tl.MatchOptions = {}; + filesList = tl.findMatch(undefined, searchPattern, findOptions, matchOptions); + } + else { + filesList = nutil.resolveFilterSpec(searchPattern); + } + tl.debug(`Found ${filesList.length} files`); filesList.forEach(file => { tl.debug(`--File: ${file}`); }); - // Getting NuGet - tl.debug('Getting NuGet'); - let nuGetPath: string = undefined; - try { - nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR]; - if (!nuGetPath){ - nuGetPath = await nuGetGetter.getNuGet("4.0.0"); - } - } - catch (error) { - tl.setResult(tl.TaskResult.Failed, error.message); - return; - } - let props: string[] = []; if(configuration && configuration !== "$(BuildConfiguration)") { @@ -128,8 +134,6 @@ export async function run(): Promise { props = props.concat(propertiesInput.split(";")); } - // TODO: Check nuget extensions path - let environmentSettings: ngToolRunner.NuGetEnvironmentSettings = { credProviderFolder: null, extensionsDisabled: true @@ -163,12 +167,15 @@ function packAsync(file: string, options: PackOptions): Q.Promise { nugetTool.arg("-NonInteractive"); + nugetTool.arg("-OutputDirectory"); if (options.outputDir) { - nugetTool.arg("-OutputDirectory"); nugetTool.arg(options.outputDir); } + else { + nugetTool.arg(path.dirname(file)); + } - if (options.properties) { + if (options.properties && options.properties.length > 0) { nugetTool.arg("-Properties"); nugetTool.arg(options.properties.join(";")); } diff --git a/Tasks/NuGetCommand/nugetpublisher.ts b/Tasks/NuGetCommand/nugetpublisher.ts index 6289ffffa8f5..20cb6837fcc1 100644 --- a/Tasks/NuGetCommand/nugetpublisher.ts +++ b/Tasks/NuGetCommand/nugetpublisher.ts @@ -33,7 +33,7 @@ class PublishOptions implements INuGetCommandOptions { ) { } } -interface VstsNuGetPushOptions { +interface IVstsNuGetPushOptions { vstsNuGetPushPath: string, feedUri: string, internalAuthInfo: auth.InternalAuthInfo, @@ -41,7 +41,7 @@ interface VstsNuGetPushOptions { settings: vstsNuGetPushToolRunner.VstsNuGetPushSettings } -export async function run(): Promise { +export async function run(nuGetPath: string): Promise { let buildIdentityDisplayName: string = null; let buildIdentityAccount: string = null; try { @@ -49,9 +49,18 @@ export async function run(): Promise { // Get list of files to pusblish let searchPattern = tl.getPathInput("searchPatternPush", true, false); - let filesList = nutil.resolveFilterSpec( - searchPattern, - tl.getVariable("System.DefaultWorkingDirectory") || process.cwd()); + + let useLegacyFind: boolean = tl.getVariable("NuGet.UseLegacyFindFiles") === "true"; + let filesList: string[] = []; + if (!useLegacyFind) { + let findOptions: tl.FindOptions = {}; + let matchOptions: tl.MatchOptions = {}; + filesList = tl.findMatch(undefined, searchPattern, findOptions, matchOptions); + } + else { + filesList = nutil.resolveFilterSpec(searchPattern); + } + filesList.forEach(packageFile => { if (!tl.stats(packageFile).isFile()) { throw new Error(tl.loc("Error_PushNotARegularFile", packageFile)); @@ -73,20 +82,6 @@ export async function run(): Promise { } nugetFeedType = normalizedNuGetFeedType; - // Getting NuGet.exe - tl.debug('Getting NuGet'); - let nuGetPath: string = undefined; - try { - nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR]; - if (!nuGetPath){ - nuGetPath = await nuGetGetter.getNuGet("4.0.0"); - } - } - catch (error) { - tl.setResult(tl.TaskResult.Failed, error.message); - return; - } - let serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false); let urlPrefixes = await locationHelpers.assumeNuGetUriPrefixes(serviceUri); tl.debug(`discovered URL prefixes: ${urlPrefixes}`); @@ -193,7 +188,7 @@ export async function run(): Promise { continueOnConflict: continueOnConflict } - let publishOptions = { + let publishOptions = { vstsNuGetPushPath: vstsPushPath, feedUri: feedUri, internalAuthInfo: authInfo.internalAuthInfo, @@ -264,7 +259,7 @@ function publishPackageNuGetAsync(packageFile: string, options: PublishOptions, return nugetTool.exec(); } -async function publishPackageVstsNuGetPushAsync(packageFile: string, options: VstsNuGetPushOptions) { +async function publishPackageVstsNuGetPushAsync(packageFile: string, options: IVstsNuGetPushOptions) { let vstsNuGetPushTool = vstsNuGetPushToolRunner.createVstsNuGetPushToolRunner(options.vstsNuGetPushPath, options.settings, options.internalAuthInfo); vstsNuGetPushTool.arg(packageFile); vstsNuGetPushTool.arg(["-Source", options.feedUri]); @@ -284,6 +279,7 @@ async function publishPackageVstsNuGetPushAsync(packageFile: string, options: Vs // ExitCode 2 means a push conflict occurred if (exitCode === 2 && options.settings.continueOnConflict) { + tl.debug(`A conflict ocurred with package ${packageFile}, ignoring it since "Allow duplicates" was selected.`) return; } @@ -303,10 +299,9 @@ function shouldUseVstsNuGetPush(isInternalFeed: boolean, conflictsAllowed: boole return false; } - // TODO check if we can verify an external feed is actually VSTS const nugetOverrideFlag = tl.getVariable("NuGet.ForceNuGetForPush"); if (nugetOverrideFlag === "true") { - tl.debug("NuGet is force enabled for publish."); + tl.debug("NuGet.exe is force enabled for publish."); if(conflictsAllowed) { tl.warning(tl.loc("Warning_ForceNuGetCannotSkipConflicts")); @@ -315,18 +310,18 @@ function shouldUseVstsNuGetPush(isInternalFeed: boolean, conflictsAllowed: boole } if (nugetOverrideFlag === "false") { - tl.debug("NuGet is force disabled for publish."); + tl.debug("NuGet.exe is force disabled for publish."); return true; } const vstsNuGetPushOverrideFlag = tl.getVariable("NuGet.ForceVstsNuGetPushForPush"); if (vstsNuGetPushOverrideFlag === "true") { - tl.debug("VstsNuGetPush is force enabled for publish."); + tl.debug("VstsNuGetPush.exe is force enabled for publish."); return true; } if (vstsNuGetPushOverrideFlag === "false") { - tl.debug("VstsNuGetPush is force disabled for publish."); + tl.debug("VstsNuGetPush.exe is force disabled for publish."); if(conflictsAllowed) { tl.warning(tl.loc("Warning_ForceNuGetCannotSkipConflicts")); diff --git a/Tasks/NuGetCommand/nugetrestore.ts b/Tasks/NuGetCommand/nugetrestore.ts index 889d0f65819e..4aabd7a335a2 100644 --- a/Tasks/NuGetCommand/nugetrestore.ts +++ b/Tasks/NuGetCommand/nugetrestore.ts @@ -1,6 +1,4 @@ import * as tl from "vsts-task-lib/task"; -// Remove once task lib 2.0.4 releases -global['_vsts_task_lib_loaded'] = true; import * as path from "path"; import * as Q from "q"; import {IExecOptions} from "vsts-task-lib/toolrunner"; @@ -34,7 +32,7 @@ class RestoreOptions implements INuGetCommandOptions { ) { } } -export async function run(): Promise { +export async function run(nuGetPath: string): Promise { let buildIdentityDisplayName: string = null; let buildIdentityAccount: string = null; @@ -45,7 +43,16 @@ export async function run(): Promise { // Reading inputs let solution = tl.getPathInput("solution", true, false); - let filesList = nutil.resolveFilterSpec(solution, tl.getVariable("System.DefaultWorkingDirectory") || process.cwd()); + let useLegacyFind: boolean = tl.getVariable("NuGet.UseLegacyFindFiles") === "true"; + let filesList: string[] = []; + if (!useLegacyFind) { + let findOptions: tl.FindOptions = {}; + let matchOptions: tl.MatchOptions = {}; + filesList = tl.findMatch(undefined, solution, findOptions, matchOptions); + } + else { + filesList = nutil.resolveFilterSpec(solution, tl.getVariable("System.DefaultWorkingDirectory") || process.cwd()); + } filesList.forEach(solutionFile => { if (!tl.stats(solutionFile).isFile()) { throw new Error(tl.loc("NotARegularFile", solutionFile)); @@ -58,20 +65,6 @@ export async function run(): Promise { packagesDirectory = null; } - // Getting NuGet - tl.debug('Getting NuGet'); - let nuGetPath: string = undefined; - try { - nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR]; - if (!nuGetPath){ - nuGetPath = await nuGetGetter.getNuGet("4.0.0"); - } - } - catch (error) { - tl.setResult(tl.TaskResult.Failed, error.message); - return; - } - const nuGetVersion: VersionInfo = await peParser.getFileVersionInfoAsync(nuGetPath); // Discovering NuGet quirks based on the version diff --git a/Tasks/NuGetCommand/package.json b/Tasks/NuGetCommand/package.json index 9cbbdd3334cc..4718f9b1f562 100644 --- a/Tasks/NuGetCommand/package.json +++ b/Tasks/NuGetCommand/package.json @@ -1,7 +1,7 @@ { "name": "nugetcommand", "version": "2.0.0", - "description": "Nuget Installer Build Task", + "description": "Restore, pack, or push NuGet packages, or run a NuGet command.", "main": "nugetcommandmain.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" @@ -17,7 +17,7 @@ }, "homepage": "https://github.com/Microsoft/vsts-tasks#readme", "dependencies": { - "vsts-task-lib": "2.0.2-preview", + "vsts-task-lib": "2.0.5", "xmlreader": "^0.2.3", "vso-node-api": "6.0.1-preview" } diff --git a/Tasks/NuGetCommand/task.json b/Tasks/NuGetCommand/task.json index 478c915f08a5..4911936e181f 100644 --- a/Tasks/NuGetCommand/task.json +++ b/Tasks/NuGetCommand/task.json @@ -29,12 +29,6 @@ "isExpanded": false, "visibleRule": "command = restore" }, - { - "name": "pushAuth", - "displayName": "Destination feed and authentication", - "isExpanded": true, - "visibleRule": "command = push" - }, { "name": "pushAdvanced", "displayName": "Advanced", @@ -88,7 +82,7 @@ "type": "radio", "label": "Feeds to use", "defaultValue": "config", - "helpMarkDown": "You can either select feeds from VSTS and/or NuGet.org here, or commit a nuget.config file to your source code repository and set its path here.", + "helpMarkDown": "You can either select a feed from VSTS and/or NuGet.org here, or commit a nuget.config file to your source code repository and set its path here.", "required": "true", "options": { "select": "Feed(s) I select here", @@ -101,7 +95,7 @@ "type": "pickList", "label": "Use packages from this VSTS/TFS feed", "defaultValue": "", - "helpMarkDown": "Include the selected feeds in the generated NuGet.config. You must have Package Management installed and licensed to select a feed here.", + "helpMarkDown": "Include the selected feed in the generated NuGet.config. You must have Package Management installed and licensed to select a feed here.", "required": "false", "groupName": "restoreAuth", "visibleRule": "selectOrConfig = select", @@ -243,7 +237,7 @@ "name": "searchPatternPack", "type": "filePath", "label": "Path to csproj or nuspec file(s) to pack", - "defaultValue": "**\\*.csproj", + "defaultValue": "**/*.csproj", "helpMarkDown": "Pattern to search for csproj or nuspec files to pack.\n\nYou can separate multiple patterns with a semicolon, and you can make a pattern negative by prefixing it with '-:'. Example: `**\\*.csproj;-:**\\*.Tests.csproj`", "required": true, "visibleRule": "command = pack" @@ -271,7 +265,7 @@ "type": "pickList", "label": "Automatic package versioning", "defaultValue": "off", - "helpMarkDown": "Cannot be used with include referenced projects. If you choose 'Use the date and time', this will generate a [SemVer](http://semver.org/spec/v1.0.0.html)-compliant version formatted as `X.Y.Z-ci-datetime` where you choose X, Y, and Z.\n\nIf you choose 'Use an environment variable', you must select an environment variable and ensure it contains the version number you want to use.\n\nIf you choose 'Use the build number', this will use the build number to version you package. **Note:** Under General set the build format to be '[$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)](https://go.microsoft.com/fwlink/?LinkID=627416)'.", + "helpMarkDown": "Cannot be used with include referenced projects. If you choose 'Use the date and time', this will generate a [SemVer](http://semver.org/spec/v1.0.0.html)-compliant version formatted as `X.Y.Z-ci-datetime` where you choose X, Y, and Z.\n\nIf you choose 'Use an environment variable', you must select an environment variable and ensure it contains the version number you want to use.\n\nIf you choose 'Use the build number', this will use the build number to version your package. **Note:** Under Options set the build number format to be '[$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)](https://go.microsoft.com/fwlink/?LinkID=627416)'.", "required": true, "groupName": "packOptions", "options": { @@ -336,7 +330,7 @@ "label": "Additional build properties", "defaultValue": "", "required": false, - "helpMarkDown": "Semicolon delimited list of properties used to build the package.", + "helpMarkDown": "Specifies a list of token=value pairs, separated by semicolons, where each occurrence of $token$ in the .nuspec file will be replaced with the given value. Values can be strings in quotation marks.", "groupName": "packAdvanced" }, { @@ -442,6 +436,9 @@ "Warning_ForceNuGetCannotSkipConflicts": "NuGet.exe was forced to be used for publish, if push conflicts occur it will result in a failure.", "Info_MatchingUrlWasFoundSettingAuth": "Using authentication information for the following URI: ", "Error_PushNotARegularFile": "%s is not a file. Check the 'Path/Pattern to nupkg' property of the task.", - "Warning_AllowDuplicatesOnlyAvailableHosted": "The 'Allow duplicates to be skipped' option is currently only available on Visual Studio Team Services. If NuGet.exe encounters a conflict, the task will fail." + "Warning_AllowDuplicatesOnlyAvailableHosted": "The 'Allow duplicates to be skipped' option is currently only available on Visual Studio Team Services. If NuGet.exe encounters a conflict, the task will fail.", + "Info_SavingTempConfig": "Saving NuGet.config to a temporary config file.", + + "Error_CommandNotRecognized": "The command %s was not recognized." } } diff --git a/Tasks/NuGetCommand/task.loc.json b/Tasks/NuGetCommand/task.loc.json index 9f4c4993086d..a4edeb5c26de 100644 --- a/Tasks/NuGetCommand/task.loc.json +++ b/Tasks/NuGetCommand/task.loc.json @@ -29,12 +29,6 @@ "isExpanded": false, "visibleRule": "command = restore" }, - { - "name": "pushAuth", - "displayName": "ms-resource:loc.group.displayName.pushAuth", - "isExpanded": true, - "visibleRule": "command = push" - }, { "name": "pushAdvanced", "displayName": "ms-resource:loc.group.displayName.pushAdvanced", @@ -240,7 +234,7 @@ "name": "searchPatternPack", "type": "filePath", "label": "ms-resource:loc.input.label.searchPatternPack", - "defaultValue": "**\\*.csproj", + "defaultValue": "**/*.csproj", "helpMarkDown": "ms-resource:loc.input.help.searchPatternPack", "required": true, "visibleRule": "command = pack" @@ -434,6 +428,8 @@ "Warning_ForceNuGetCannotSkipConflicts": "ms-resource:loc.messages.Warning_ForceNuGetCannotSkipConflicts", "Info_MatchingUrlWasFoundSettingAuth": "ms-resource:loc.messages.Info_MatchingUrlWasFoundSettingAuth", "Error_PushNotARegularFile": "ms-resource:loc.messages.Error_PushNotARegularFile", - "Warning_AllowDuplicatesOnlyAvailableHosted": "ms-resource:loc.messages.Warning_AllowDuplicatesOnlyAvailableHosted" + "Warning_AllowDuplicatesOnlyAvailableHosted": "ms-resource:loc.messages.Warning_AllowDuplicatesOnlyAvailableHosted", + "Info_SavingTempConfig": "ms-resource:loc.messages.Info_SavingTempConfig", + "Error_CommandNotRecognized": "ms-resource:loc.messages.Error_CommandNotRecognized" } } \ No newline at end of file diff --git a/make-options.json b/make-options.json index 9410d651d6f4..b254fd5d6604 100644 --- a/make-options.json +++ b/make-options.json @@ -49,7 +49,7 @@ "NuGet", "NugetPackager", "NuGetPublisher", - "NuGetRestore", + "NuGetCommand", "NuGetToolInstaller", "PackerBuild", "DownloadPackage",