@@ -22,14 +22,18 @@ enum NuGetReleaseStage
2222
2323const NUGET_TOOL_NAME : string = 'NuGet' ;
2424const NUGET_EXE_FILENAME : string = 'nuget.exe' ;
25- const NUGET_VERSION_4_0_0 : string = '4.0.0' ;
2625
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/' ;
2731export const NUGET_EXE_TOOL_PATH_ENV_VAR : string = 'NuGetExeToolPath' ;
2832
2933export async function getNuGet ( versionSpec : string , checkLatest ?: boolean , addNuGetToPath ?: boolean ) : Promise < string > {
3034 if ( toolLib . isExplicitVersion ( versionSpec ) ) {
3135 // Check latest doesn't make sense when explicit version
32- checkLatest = false ;
36+ checkLatest = false ;
3337 taskLib . debug ( 'Exact match expected on version: ' + versionSpec ) ;
3438 }
3539 else {
@@ -65,7 +69,7 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
6569
6670 if ( ! versionInfo . url )
6771 {
68- taskLib . error ( taskLib . loc ( "Error_NoUrlWasFoundWhichMatches" , version ) ) ;
72+ taskLib . error ( taskLib . loc ( "Error_NoUrlWasFoundWhichMatches" , version ) ) ;
6973 throw new Error ( taskLib . loc ( "Error_NuGetToolInstallerFailer" , NUGET_TOOL_NAME ) ) ;
7074 }
7175
@@ -94,12 +98,20 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
9498 return fullNuGetPath ;
9599}
96100
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 ) ;
103115 }
104116}
105117
@@ -115,10 +127,10 @@ function GetRestClientOptions(): restm.IRequestOptions
115127
116128async function getLatestMatchVersionInfo ( versionSpec : string ) : Promise < INuGetVersionInfo > {
117129 taskLib . debug ( 'Querying versions list' ) ;
118-
130+
119131 let versionsUrl = 'https://dist.nuget.org/tools.json' ;
120132 let rest : restm . RestClient = new restm . RestClient ( 'vsts-tasks/NuGetToolInstaller' ) ;
121-
133+
122134 let nugetVersions : INuGetVersionInfo [ ] = ( await rest . get < INuGetVersionInfo [ ] > ( versionsUrl , GetRestClientOptions ( ) ) ) . result ;
123135 // x.stage is the string representation of the enum, NuGetReleaseStage.Value = number, NuGetReleaseStage[NuGetReleaseStage.Value] = string, NuGetReleaseStage[x.stage] = number
124136 let releasedVersions : INuGetVersionInfo [ ] = nugetVersions . filter ( x => x . stage . toString ( ) !== NuGetReleaseStage [ NuGetReleaseStage . EarlyAccessPreview ] ) ;
@@ -127,7 +139,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
127139 let version : string = toolLib . evaluateVersions ( versionStringsFromDist , versionSpec ) ;
128140 if ( ! version )
129141 {
130- taskLib . error ( taskLib . loc ( "Error_NoVersionWasFoundWhichMatches" , versionSpec ) ) ;
142+ taskLib . error ( taskLib . loc ( "Error_NoVersionWasFoundWhichMatches" , versionSpec ) ) ;
131143 taskLib . error ( taskLib . loc ( "Info_AvailableVersions" , releasedVersions . map ( x => x . version ) . join ( "; " ) ) ) ;
132144 throw new Error ( taskLib . loc ( "Error_NuGetToolInstallerFailer" , NUGET_TOOL_NAME ) ) ;
133145 }
@@ -136,10 +148,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
136148}
137149
138150
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 {
143152 let taskNodeModulesPath : string = path . dirname ( __dirname ) ;
144153 let taskRootPath : string = path . dirname ( taskNodeModulesPath ) ;
145154 const toolPath = commandHelper . locateTool ( "NuGet" ,
0 commit comments