Skip to content

Commit aa304f6

Browse files
authored
Merge pull request #2372 from kkdawkins/master (#2540)
NuGet UX Work for Multiple Versions of NuGet
1 parent 8d41aa9 commit aa304f6

File tree

13 files changed

+186
-84
lines changed

13 files changed

+186
-84
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const nuget320 = new VersionInfoVersion(3, 2, 0, 0);
5858
const nuget330 = new VersionInfoVersion(3, 3, 0, 0);
5959
const nuget340 = new VersionInfoVersion(3, 4, 0, 0);
6060
const nuget350_1707 = new VersionInfoVersion(3, 5, 0, 1707);
61+
const nuget350_1829 = new VersionInfoVersion(3, 5, 0, 1829);
6162
const nuget351 = new VersionInfoVersion(3, 5, 1, 0);
6263
const nuget351_1707 = new VersionInfoVersion(3, 5, 1, 1707);
6364

@@ -93,7 +94,7 @@ const allQuirks: QuirkDescriptor[] = [
9394
},
9495
{
9596
quirk: NuGetQuirkName.NoTfsOnPremAuthCredentialProvider,
96-
versionRanges: [halfOpenRange(VersionInfoVersion.MIN_VERSION, nuget351)],
97+
versionRanges: [halfOpenRange(VersionInfoVersion.MIN_VERSION, nuget350_1829)],
9798
},
9899
];
99100

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,5 @@ export function isCredentialConfigEnabled(quirks: NuGetQuirks): boolean {
271271
}
272272

273273
export function locateCredentialProvider(): string {
274-
const credentialProviderLocation = locateTool("CredentialProvider.TeamBuild.exe");
275-
if (!credentialProviderLocation) {
276-
tl.debug("Credential provider is not present.");
277-
return null;
278-
}
279-
280-
return credentialProviderLocation;
274+
return path.join(__dirname, 'NuGet/CredentialProvider');
281275
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,13 @@ export function stripLeadingAndTrailingQuotes(path: string): string {
138138
// substring returns a value *not* including the character at right
139139
return path.substring(left, right + 1);
140140
}
141+
142+
export function getBundledNuGetLocation(version: string): string {
143+
if (version === "3.5.0.1829"){
144+
return path.join(__dirname, 'NuGet/3.5.0.1829/NuGet.exe')
145+
}
146+
else if (version === "3.3.0"){
147+
return path.join(__dirname, 'NuGet/3.3.0/NuGet.exe');
148+
}
149+
throw new Error(tl.loc("NGCommon_UnabletoDetectNuGetVersion"));
150+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"archivePackages": [
3+
{
4+
"archiveName": "NuGet.exe",
5+
"url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/3.3.0/nuget.zip",
6+
"dest": "./NuGet/3.3.0/"
7+
},
8+
{
9+
"archiveName": "NuGet.exe",
10+
"url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/3.5.0-1829/NuGet.zip",
11+
"dest": "./NuGet/3.5.0.1829/"
12+
},
13+
{
14+
"archiveName": "CredentialProvider.TeamBuild.exe",
15+
"url": "https://vstsagenttools.blob.core.windows.net/tools/CredentialProvider.TeamBuild/15.105.25712.0/CredentialProvider.TeamBuild.zip",
16+
"dest": "./NuGet/CredentialProvider/"
17+
}
18+
]
19+
}

Tasks/NuGetInstaller/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
"loc.input.help.nuGetRestoreArgs": "Additional arguments passed to NuGet.exe restore or install. [More Information](https://docs.nuget.org/consume/command-line-reference#user-content-restore-command).",
1717
"loc.input.label.verbosity": "Verbosity",
1818
"loc.input.help.verbosity": "NuGet's verbosity level",
19+
"loc.input.label.nuGetVersion": "NuGet Version",
20+
"loc.input.help.nuGetVersion": "The version of NuGet to use, or external verson.",
1921
"loc.input.label.nuGetPath": "Path to NuGet.exe",
20-
"loc.input.help.nuGetPath": "Optionally supply the path to NuGet.exe",
21-
"loc.input.label.preCredProviderNuGet": "Path to NuGet.exe is below version 3.2",
22-
"loc.input.help.preCredProviderNuGet": "If you are supplying a path to nuget.exe and it is older than NuGet 3.2, check this box and fill in a 'Path to NuGet.config' above. Has no effect if 'Path to NuGet.exe' is not specified.",
22+
"loc.input.help.nuGetPath": "Optionally supply the path to NuGet.exe. Will override version selection.",
2323
"loc.messages.Warning_NoConfigForOldNuGet": "To connect to NuGet feeds hosted in your Team Services account/TFS project collection with NuGet 3.1 or below, edit your build definition to specify a path to a NuGet.config containing the package sources you wish to use.",
2424
"loc.messages.Warning_NoConfigForNoCredentialProvider": "To connect to NuGet feeds hosted in your Team Services account/TFS project collection on this build agent, edit your build definition to specify a path to a NuGet.config containing the package sources you wish to use.",
25+
"loc.messages.Warning_ConflictingNuGetPreference": "NuGet 3.3 was selected, but a custom NuGet path was provided. The custom path will be preferred. To resolve this warning, edit your build task and select 'custom' for NuGet version under Advanced.",
2526
"loc.messages.PackagesInstalledSuccessfully": "Packages were installed successfully",
2627
"loc.messages.PackagesFailedToInstall": "Packages failed to install",
2728
"loc.messages.ConnectingAs": "Connecting to feeds in your Team Services account/TFS project collection as '%s' [%s]",
@@ -30,6 +31,7 @@
3031
"loc.messages.NotARegularFile": "%s i not a solution file. Check the 'path to solution or packages.config' property of the NuGetInstaller task.",
3132
"loc.messages.UnknownRestoreMode": "Unknown restore mode '%s'",
3233
"loc.messages.CouldNotFindNuGetService": "Could not find the NuGet service. This task will be unable to authenticate to feeds hosted in your Team Services account/TFS project collection.",
34+
"loc.messages.NoNuGetSpecified": "If 'custom' is selected, you must provide a path to NuGet.exe",
3335
"loc.messages.NGCommon_DetectedNuGetVersion": "Detected NuGet version %s / %s",
3436
"loc.messages.NGCommon_IgnoringNuGetExtensionsPath": "Detected NuGet extensions loader path (NUGET_EXTENSIONS_PATH environment variable). Extensions are ignored when using the built-in NuGet client",
3537
"loc.messages.NGCommon_DetectedNuGetExtensionsPath": "Detected NuGet extensions loader path (NUGET_EXTENSIONS_PATH environment variable): %s",
@@ -40,5 +42,6 @@
4042
"loc.messages.NGCommon_NuGetConfigIsInvalid": "The NuGet.config at %s is invalid.",
4143
"loc.messages.NGCommon_RemovingSources": "Preparing to set credentials in NuGet.config",
4244
"loc.messages.NGCommon_AddingSources": "Setting credentials in NuGet.config",
43-
"loc.messages.NGCommon_NoSourcesFoundInConfig": "No package sources were found in the NuGet.config file at %s"
45+
"loc.messages.NGCommon_NoSourcesFoundInConfig": "No package sources were found in the NuGet.config file at %s",
46+
"loc.messages.NGCommon_UnabletoDetectNuGetVersion": "Unknown NuGet version selected."
4447
}

Tasks/NuGetInstaller/nugetinstaller.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,37 @@ async function main(): Promise<void> {
6767
nugetConfigPath = null;
6868
}
6969

70+
let nugetVersion = tl.getInput('nuGetVersion');
71+
7072
// due to a bug where we accidentally allowed nuGetPath to be surrounded by quotes before,
7173
// locateNuGetExe() will strip them and check for existence there.
72-
let userNuGetPath = tl.getPathInput("nuGetPath", false, false);
73-
if (!tl.filePathSupplied("nuGetPath")) {
74-
userNuGetPath = null;
74+
let nuGetPath = tl.getPathInput("nuGetPath", false, false);
75+
let userNuGetProvided = false;
76+
if(tl.filePathSupplied("nuGetPath")){
77+
nuGetPath = nutil.stripLeadingAndTrailingQuotes(nuGetPath);
78+
// True if the user provided their own version of NuGet
79+
userNuGetProvided = true;
80+
if (nugetVersion !== "custom"){
81+
// For back compat, if a path has already been specificed then use it.
82+
// However warn the user in the build of this behavior
83+
tl.warning(tl.loc("Warning_ConflictingNuGetPreference"));
84+
}
85+
}
86+
else {
87+
if (nugetVersion === "custom")
88+
{
89+
throw new Error(tl.loc("NoNuGetSpecified"))
90+
}
91+
// Pull the pre-installed path for NuGet.
92+
nuGetPath = nutil.getBundledNuGetLocation(nugetVersion);
7593
}
7694

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

79-
// find nuget location to use
80-
let nuGetPathToUse = ngToolRunner.locateNuGetExe(userNuGetPath);
97+
//find nuget location to use
8198
let credProviderPath = ngToolRunner.locateCredentialProvider();
8299

83-
const quirks = await ngToolRunner.getNuGetQuirksAsync(nuGetPathToUse);
100+
const quirks = await ngToolRunner.getNuGetQuirksAsync(nuGetPath);
84101

85102
// clauses ordered in this way to avoid short-circuit evaluation, so the debug info printed by the functions
86103
// is unconditionally displayed
@@ -103,15 +120,15 @@ async function main(): Promise<void> {
103120
let environmentSettings: ngToolRunner.NuGetEnvironmentSettings = {
104121
authInfo: authInfo,
105122
credProviderFolder: useCredProvider ? path.dirname(credProviderPath) : null,
106-
extensionsDisabled: !userNuGetPath,
123+
extensionsDisabled: !userNuGetProvided
107124
};
108125

109126
let configFile = nugetConfigPath;
110127
let credCleanup = () => { return; };
111128
if (useCredConfig) {
112129
if (nugetConfigPath) {
113130
let nuGetConfigHelper = new NuGetConfigHelper(
114-
nuGetPathToUse,
131+
nuGetPath,
115132
nugetConfigPath,
116133
authInfo,
117134
environmentSettings);
@@ -136,7 +153,7 @@ async function main(): Promise<void> {
136153
try {
137154
let restoreOptions = new RestoreOptions(
138155
restoreMode,
139-
nuGetPathToUse,
156+
nuGetPath,
140157
configFile,
141158
noCache,
142159
verbosity,

Tasks/NuGetInstaller/task.json

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 2,
12-
"Patch": 15
12+
"Patch": 16
1313
},
1414
"minimumAgentVersion": "1.83.0",
1515
"groups": [
@@ -79,25 +79,30 @@
7979
"Normal": "Normal",
8080
"Detailed": "Detailed"
8181
}
82+
},
83+
{
84+
"name": "nuGetVersion",
85+
"type": "radio",
86+
"label": "NuGet Version",
87+
"defaultValue": "3.3.0",
88+
"helpMarkDown": "The version of NuGet to use, or external verson.",
89+
"required": "true",
90+
"groupName": "advanced",
91+
"options": {
92+
"3.3.0": "3.3.0",
93+
"3.5.0.1829": "3.5.0 – build 1829 (rc2)",
94+
"custom" : "Custom"
95+
}
8296
},
8397
{
8498
"name": "nuGetPath",
8599
"type": "string",
86100
"label": "Path to NuGet.exe",
87101
"defaultValue": "",
88102
"required": false,
89-
"helpMarkDown": "Optionally supply the path to NuGet.exe",
103+
"helpMarkDown": "Optionally supply the path to NuGet.exe. Will override version selection.",
90104
"groupName": "advanced"
91-
},
92-
{
93-
"name": "preCredProviderNuGet",
94-
"type": "boolean",
95-
"label": "Path to NuGet.exe is below version 3.2",
96-
"groupName": "advanced",
97-
"defaultValue": "false",
98-
"helpMarkDown": "If you are supplying a path to nuget.exe and it is older than NuGet 3.2, check this box and fill in a 'Path to NuGet.config' above. Has no effect if 'Path to NuGet.exe' is not specified.",
99-
"required": "false"
100-
}
105+
}
101106
],
102107
"execution": {
103108
"Node": {
@@ -108,6 +113,7 @@
108113
"messages": {
109114
"Warning_NoConfigForOldNuGet": "To connect to NuGet feeds hosted in your Team Services account/TFS project collection with NuGet 3.1 or below, edit your build definition to specify a path to a NuGet.config containing the package sources you wish to use.",
110115
"Warning_NoConfigForNoCredentialProvider": "To connect to NuGet feeds hosted in your Team Services account/TFS project collection on this build agent, edit your build definition to specify a path to a NuGet.config containing the package sources you wish to use.",
116+
"Warning_ConflictingNuGetPreference" : "NuGet 3.3 was selected, but a custom NuGet path was provided. The custom path will be preferred. To resolve this warning, edit your build task and select 'custom' for NuGet version under Advanced.",
111117
"PackagesInstalledSuccessfully": "Packages were installed successfully",
112118
"PackagesFailedToInstall": "Packages failed to install",
113119
"ConnectingAs": "Connecting to feeds in your Team Services account/TFS project collection as '%s' [%s]",
@@ -116,6 +122,7 @@
116122
"NotARegularFile": "%s i not a solution file. Check the 'path to solution or packages.config' property of the NuGetInstaller task.",
117123
"UnknownRestoreMode": "Unknown restore mode '%s'",
118124
"CouldNotFindNuGetService": "Could not find the NuGet service. This task will be unable to authenticate to feeds hosted in your Team Services account/TFS project collection.",
125+
"NoNuGetSpecified" : "If 'custom' is selected, you must provide a path to NuGet.exe",
119126

120127
"NGCommon_DetectedNuGetVersion": "Detected NuGet version %s / %s",
121128
"NGCommon_IgnoringNuGetExtensionsPath": "Detected NuGet extensions loader path (NUGET_EXTENSIONS_PATH environment variable). Extensions are ignored when using the built-in NuGet client",
@@ -127,7 +134,8 @@
127134
"NGCommon_NuGetConfigIsInvalid": "The NuGet.config at %s is invalid.",
128135
"NGCommon_RemovingSources": "Preparing to set credentials in NuGet.config",
129136
"NGCommon_AddingSources": "Setting credentials in NuGet.config",
130-
"NGCommon_NoSourcesFoundInConfig": "No package sources were found in the NuGet.config file at %s"
137+
"NGCommon_NoSourcesFoundInConfig": "No package sources were found in the NuGet.config file at %s",
138+
"NGCommon_UnabletoDetectNuGetVersion" : "Unknown NuGet version selected."
131139

132140
}
133141
}

Tasks/NuGetInstaller/task.loc.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 2,
12-
"Patch": 15
12+
"Patch": 16
1313
},
1414
"minimumAgentVersion": "1.83.0",
1515
"groups": [
@@ -80,6 +80,20 @@
8080
"Detailed": "Detailed"
8181
}
8282
},
83+
{
84+
"name": "nuGetVersion",
85+
"type": "radio",
86+
"label": "ms-resource:loc.input.label.nuGetVersion",
87+
"defaultValue": "3.3.0",
88+
"helpMarkDown": "ms-resource:loc.input.help.nuGetVersion",
89+
"required": "true",
90+
"groupName": "advanced",
91+
"options": {
92+
"3.3.0": "3.3.0",
93+
"3.5.0.1829": "3.5.0 – build 1829 (rc2)",
94+
"custom": "Custom"
95+
}
96+
},
8397
{
8498
"name": "nuGetPath",
8599
"type": "string",
@@ -88,15 +102,6 @@
88102
"required": false,
89103
"helpMarkDown": "ms-resource:loc.input.help.nuGetPath",
90104
"groupName": "advanced"
91-
},
92-
{
93-
"name": "preCredProviderNuGet",
94-
"type": "boolean",
95-
"label": "ms-resource:loc.input.label.preCredProviderNuGet",
96-
"groupName": "advanced",
97-
"defaultValue": "false",
98-
"helpMarkDown": "ms-resource:loc.input.help.preCredProviderNuGet",
99-
"required": "false"
100105
}
101106
],
102107
"execution": {
@@ -108,6 +113,7 @@
108113
"messages": {
109114
"Warning_NoConfigForOldNuGet": "ms-resource:loc.messages.Warning_NoConfigForOldNuGet",
110115
"Warning_NoConfigForNoCredentialProvider": "ms-resource:loc.messages.Warning_NoConfigForNoCredentialProvider",
116+
"Warning_ConflictingNuGetPreference": "ms-resource:loc.messages.Warning_ConflictingNuGetPreference",
111117
"PackagesInstalledSuccessfully": "ms-resource:loc.messages.PackagesInstalledSuccessfully",
112118
"PackagesFailedToInstall": "ms-resource:loc.messages.PackagesFailedToInstall",
113119
"ConnectingAs": "ms-resource:loc.messages.ConnectingAs",
@@ -116,6 +122,7 @@
116122
"NotARegularFile": "ms-resource:loc.messages.NotARegularFile",
117123
"UnknownRestoreMode": "ms-resource:loc.messages.UnknownRestoreMode",
118124
"CouldNotFindNuGetService": "ms-resource:loc.messages.CouldNotFindNuGetService",
125+
"NoNuGetSpecified": "ms-resource:loc.messages.NoNuGetSpecified",
119126
"NGCommon_DetectedNuGetVersion": "ms-resource:loc.messages.NGCommon_DetectedNuGetVersion",
120127
"NGCommon_IgnoringNuGetExtensionsPath": "ms-resource:loc.messages.NGCommon_IgnoringNuGetExtensionsPath",
121128
"NGCommon_DetectedNuGetExtensionsPath": "ms-resource:loc.messages.NGCommon_DetectedNuGetExtensionsPath",
@@ -126,6 +133,7 @@
126133
"NGCommon_NuGetConfigIsInvalid": "ms-resource:loc.messages.NGCommon_NuGetConfigIsInvalid",
127134
"NGCommon_RemovingSources": "ms-resource:loc.messages.NGCommon_RemovingSources",
128135
"NGCommon_AddingSources": "ms-resource:loc.messages.NGCommon_AddingSources",
129-
"NGCommon_NoSourcesFoundInConfig": "ms-resource:loc.messages.NGCommon_NoSourcesFoundInConfig"
136+
"NGCommon_NoSourcesFoundInConfig": "ms-resource:loc.messages.NGCommon_NoSourcesFoundInConfig",
137+
"NGCommon_UnabletoDetectNuGetVersion": "ms-resource:loc.messages.NGCommon_UnabletoDetectNuGetVersion"
130138
}
131139
}

Tasks/NugetPublisher/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
"loc.input.help.nuGetAdditionalArgs": "Additional arguments passed to NuGet.exe push. [More Information](https://docs.nuget.org/consume/command-line-reference#user-content-push-command).",
1616
"loc.input.label.verbosity": "Verbosity",
1717
"loc.input.help.verbosity": "NuGet's verbosity level",
18+
"loc.input.label.nuGetVersion": "NuGet Version",
19+
"loc.input.help.nuGetVersion": "The version of NuGet to use, or custom verson.",
1820
"loc.input.label.nuGetPath": "Path to NuGet.exe",
19-
"loc.input.help.nuGetPath": "Optionally supply the path to NuGet.exe",
20-
"loc.input.label.preCredProviderNuGet": "Path to NuGet.exe is below version 3.2",
21-
"loc.input.help.preCredProviderNuGet": "If you are supplying a path to nuget.exe and it is older than NuGet 3.2, check this box and fill in a 'Path to NuGet.config' above. Has no effect if 'Path to NuGet.exe' is not specified.",
21+
"loc.input.help.nuGetPath": "Optionally supply the path to NuGet.exe. Will override version selection.",
2222
"loc.messages.Warning_NoConfigForOldNuGet": "To connect to NuGet feeds hosted in your Team Services account/TFS project collection with NuGet 3.1 or below, edit your build definition to specify a path to a NuGet.config containing the package sources you wish to use.",
2323
"loc.messages.Warning_NoConfigForNoCredentialProvider": "To connect to NuGet feeds hosted in your Team Services account/TFS project collection on this build agent, edit your build definition to specify a path to a NuGet.config containing the package sources you wish to use.",
24+
"loc.messages.Warning_ConflictingNuGetPreference": "NuGet 3.3 was selected, but a custom NuGet path was provided. The custom path will be preferred. To resolve this warning, edit your build task and select 'custom' for NuGet version under Advanced.",
2425
"loc.messages.PackagesPublishedSuccessfully": "Packages were published successfully",
2526
"loc.messages.PackagesFailedToPublish": "Packages failed to publish",
2627
"loc.messages.ConnectingAs": "Connecting to feeds in your Team Services account/TFS project collection as '%s' [%s]",
@@ -29,6 +30,7 @@
2930
"loc.messages.NotARegularFile": "%s is not a regular file. Check the 'Path/Pattern to nupkg' property of the NuGetPublisher task.",
3031
"loc.messages.UnknownFeedType": "Unknown feed type '%s'",
3132
"loc.messages.CouldNotFindNuGetService": "Could not find the NuGet service. This task will be unable to authenticate to feeds hosted in your Team Services account/TFS project collection.",
33+
"loc.messages.NoNuGetSpecified": "If 'custom' is selected, you must provide a path to NuGet.exe",
3234
"loc.messages.NGCommon_DetectedNuGetVersion": "Detected NuGet version %s / %s",
3335
"loc.messages.NGCommon_IgnoringNuGetExtensionsPath": "Detected NuGet extensions loader path (NUGET_EXTENSIONS_PATH environment variable). Extensions are ignored when using the built-in NuGet client",
3436
"loc.messages.NGCommon_DetectedNuGetExtensionsPath": "Detected NuGet extensions loader path (NUGET_EXTENSIONS_PATH environment variable): %s",
@@ -39,5 +41,6 @@
3941
"loc.messages.NGCommon_NuGetConfigIsInvalid": "The NuGet.config at %s is invalid.",
4042
"loc.messages.NGCommon_RemovingSources": "Preparing to set credentials in NuGet.config",
4143
"loc.messages.NGCommon_AddingSources": "Setting credentials in NuGet.config",
42-
"loc.messages.NGCommon_NoSourcesFoundInConfig": "No package sources were found in the NuGet.config file at %s"
44+
"loc.messages.NGCommon_NoSourcesFoundInConfig": "No package sources were found in the NuGet.config file at %s",
45+
"loc.messages.NGCommon_UnabletoDetectNuGetVersion": "Unknown NuGet version selected."
4346
}

0 commit comments

Comments
 (0)