@@ -106,15 +106,24 @@ interface LocateOptions {
106106
107107 /** Array of filenames to use when searching for the tool. Defaults to the tool name. */
108108 toolFilenames ?: string [ ] ;
109+
110+ /** Array of paths to search under. Defaults to agent NuGet locations */
111+ searchPath ?: string [ ] ;
112+
113+ /** root that searchPaths are relative to. Defaults to the Agent.HomeDirectory build variable */
114+ root ?: string ;
109115}
110116
111117function locateTool ( tool : string , opts ?: LocateOptions ) {
112- let searchPath = [ "externals/nuget" , "agent/Worker/Tools/NuGetCredentialProvider" , "agent/Worker/Tools" ] ;
113- let agentRoot = tl . getVariable ( "Agent.HomeDirectory" ) ;
118+ const defaultSearchPath = [ "externals/nuget" , "agent/Worker/Tools/NuGetCredentialProvider" , "agent/Worker/Tools" ] ;
119+ const defaultAgentRoot = tl . getVariable ( "Agent.HomeDirectory" ) ;
114120
115121 opts = opts || { } ;
116122 opts . toolFilenames = opts . toolFilenames || [ tool ] ;
117123
124+ let searchPath = opts . searchPath || defaultSearchPath ;
125+ let agentRoot = opts . root || defaultAgentRoot ;
126+
118127 tl . debug ( `looking for tool ${ tool } ` ) ;
119128
120129 for ( let thisVariant of opts . toolFilenames ) {
@@ -271,5 +280,24 @@ export function isCredentialConfigEnabled(quirks: NuGetQuirks): boolean {
271280}
272281
273282export function locateCredentialProvider ( ) : string {
274- return path . join ( __dirname , ' NuGet/CredentialProvider' ) ;
283+ return path . join ( __dirname , " NuGet/CredentialProvider" ) ;
275284}
285+
286+ export function getBundledNuGetLocation ( uxOption : string ) : string {
287+ let nuGetDir ;
288+ if ( uxOption === "3.5.0.1829" ) {
289+ nuGetDir = "NuGet/3.5.0" ;
290+ }
291+ else if ( uxOption === "3.3.0" ) {
292+ nuGetDir = "NuGet/3.3.0" ;
293+ }
294+ else {
295+ throw new Error ( tl . loc ( "NGCommon_UnabletoDetectNuGetVersion" ) ) ;
296+ }
297+
298+ return locateTool ( "NuGet" , {
299+ root : __dirname ,
300+ searchPath : [ nuGetDir ] ,
301+ toolFilenames : [ "NuGet.exe" , "nuget.exe" ] ,
302+ } ) ;
303+ }
0 commit comments