@@ -22,14 +22,18 @@ enum NuGetReleaseStage
22
22
23
23
const NUGET_TOOL_NAME : string = 'NuGet' ;
24
24
const NUGET_EXE_FILENAME : string = 'nuget.exe' ;
25
- const NUGET_VERSION_4_0_0 : string = '4.0.0' ;
26
25
26
+ export const FORCE_NUGET_4_0_0 : string = 'FORCE_NUGET_4_0_0' ;
27
+ export const NUGET_VERSION_4_0_0 : string = '4.0.0' ;
28
+ export const NUGET_VERSION_4_0_0_PATH_SUFFIX : string = 'NuGet/4.0.0/' ;
29
+ export const DEFAULT_NUGET_VERSION : string = '4.1.0' ;
30
+ export const DEFAULT_NUGET_PATH_SUFFIX : string = 'NuGet/4.1.0/' ;
27
31
export const NUGET_EXE_TOOL_PATH_ENV_VAR : string = 'NuGetExeToolPath' ;
28
32
29
33
export async function getNuGet ( versionSpec : string , checkLatest ?: boolean , addNuGetToPath ?: boolean ) : Promise < string > {
30
34
if ( toolLib . isExplicitVersion ( versionSpec ) ) {
31
35
// Check latest doesn't make sense when explicit version
32
- checkLatest = false ;
36
+ checkLatest = false ;
33
37
taskLib . debug ( 'Exact match expected on version: ' + versionSpec ) ;
34
38
}
35
39
else {
@@ -65,7 +69,7 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
65
69
66
70
if ( ! versionInfo . url )
67
71
{
68
- taskLib . error ( taskLib . loc ( "Error_NoUrlWasFoundWhichMatches" , version ) ) ;
72
+ taskLib . error ( taskLib . loc ( "Error_NoUrlWasFoundWhichMatches" , version ) ) ;
69
73
throw new Error ( taskLib . loc ( "Error_NuGetToolInstallerFailer" , NUGET_TOOL_NAME ) ) ;
70
74
}
71
75
@@ -94,12 +98,20 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
94
98
return fullNuGetPath ;
95
99
}
96
100
97
- export async function cacheBundledNuGet_4_0_0 ( ) {
98
- if ( ! toolLib . findLocalTool ( NUGET_TOOL_NAME , NUGET_VERSION_4_0_0 ) ) {
99
- taskLib . debug ( 'Placing bundled NuGet.exe 4.0.0 in tool lib cache' ) ;
100
-
101
- let bundledNuGet4Location : string = getBundledNuGet_4_0_0_Location ( ) ;
102
- toolLib . cacheFile ( bundledNuGet4Location , NUGET_EXE_FILENAME , NUGET_TOOL_NAME , NUGET_VERSION_4_0_0 ) ;
101
+ export async function cacheBundledNuGet ( ) {
102
+ let cachedVersionToUse = DEFAULT_NUGET_VERSION ;
103
+ let nugetPathSuffix = DEFAULT_NUGET_PATH_SUFFIX ;
104
+ if ( taskLib . getVariable ( FORCE_NUGET_4_0_0 ) &&
105
+ taskLib . getVariable ( FORCE_NUGET_4_0_0 ) . toLowerCase ( ) === "true" ) {
106
+ cachedVersionToUse = NUGET_VERSION_4_0_0 ;
107
+ nugetPathSuffix = NUGET_VERSION_4_0_0_PATH_SUFFIX ;
108
+ }
109
+
110
+ if ( ! toolLib . findLocalTool ( NUGET_TOOL_NAME , cachedVersionToUse ) ) {
111
+ taskLib . debug ( `Placing bundled NuGet.exe ${ cachedVersionToUse } in tool lib cache` ) ;
112
+
113
+ let bundledNuGet4Location : string = getBundledNuGet_Location ( [ nugetPathSuffix ] ) ;
114
+ toolLib . cacheFile ( bundledNuGet4Location , NUGET_EXE_FILENAME , NUGET_TOOL_NAME , cachedVersionToUse ) ;
103
115
}
104
116
}
105
117
@@ -115,10 +127,10 @@ function GetRestClientOptions(): restm.IRequestOptions
115
127
116
128
async function getLatestMatchVersionInfo ( versionSpec : string ) : Promise < INuGetVersionInfo > {
117
129
taskLib . debug ( 'Querying versions list' ) ;
118
-
130
+
119
131
let versionsUrl = 'https://dist.nuget.org/tools.json' ;
120
132
let rest : restm . RestClient = new restm . RestClient ( 'vsts-tasks/NuGetToolInstaller' ) ;
121
-
133
+
122
134
let nugetVersions : INuGetVersionInfo [ ] = ( await rest . get < INuGetVersionInfo [ ] > ( versionsUrl , GetRestClientOptions ( ) ) ) . result ;
123
135
// x.stage is the string representation of the enum, NuGetReleaseStage.Value = number, NuGetReleaseStage[NuGetReleaseStage.Value] = string, NuGetReleaseStage[x.stage] = number
124
136
let releasedVersions : INuGetVersionInfo [ ] = nugetVersions . filter ( x => x . stage . toString ( ) !== NuGetReleaseStage [ NuGetReleaseStage . EarlyAccessPreview ] ) ;
@@ -127,7 +139,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
127
139
let version : string = toolLib . evaluateVersions ( versionStringsFromDist , versionSpec ) ;
128
140
if ( ! version )
129
141
{
130
- taskLib . error ( taskLib . loc ( "Error_NoVersionWasFoundWhichMatches" , versionSpec ) ) ;
142
+ taskLib . error ( taskLib . loc ( "Error_NoVersionWasFoundWhichMatches" , versionSpec ) ) ;
131
143
taskLib . error ( taskLib . loc ( "Info_AvailableVersions" , releasedVersions . map ( x => x . version ) . join ( "; " ) ) ) ;
132
144
throw new Error ( taskLib . loc ( "Error_NuGetToolInstallerFailer" , NUGET_TOOL_NAME ) ) ;
133
145
}
@@ -136,10 +148,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
136
148
}
137
149
138
150
139
-
140
- function getBundledNuGet_4_0_0_Location ( ) : string {
141
- const nugetPaths : string [ ] = [ 'NuGet/4.0.0/' ] ;
142
-
151
+ function getBundledNuGet_Location ( nugetPaths : string [ ] ) : string {
143
152
let taskNodeModulesPath : string = path . dirname ( __dirname ) ;
144
153
let taskRootPath : string = path . dirname ( taskNodeModulesPath ) ;
145
154
const toolPath = commandHelper . locateTool ( "NuGet" ,
0 commit comments