@@ -91,28 +91,24 @@ export function createNuGetToolRunner(nuGetExePath: string, settings: NuGetEnvir
9191 return runner ;
9292}
9393
94- export interface LocateOptions {
95- optional ?: boolean ;
96- userPath ?: string ;
94+ interface LocateOptions {
95+ /** if true, search along the system path in addition to the hard-coded NuGet tool paths */
9796 fallbackToSystemPath ?: boolean ;
97+
98+ /** Array of filenames to use when searching for the tool. Defaults to the tool name. */
99+ toolFilenames ?: string [ ] ;
98100}
99101
100- export function locateTool ( tool : string | string [ ] , opts ?: LocateOptions ) {
101- let toolVariants : string [ ] = typeof tool === 'string' ? [ tool ] : tool ;
102+ function locateTool ( tool : string , opts ?: LocateOptions ) {
102103 let searchPath = [ "externals/nuget" , "agent/Worker/Tools/NuGetCredentialProvider" , "agent/Worker/Tools" ] ;
103104 let agentRoot = tl . getVariable ( "Agent.HomeDirectory" ) ;
104105
105106 opts = opts || { } ;
107+ opts . toolFilenames = opts . toolFilenames || [ tool ] ;
106108
107109 tl . debug ( `looking for tool ${ tool } ` )
108110
109- if ( opts . userPath ) {
110- tl . debug ( `using user-supplied path ${ opts . userPath } ` )
111- tl . checkPath ( opts . userPath , toolVariants [ 0 ] ) ;
112- return opts . userPath ;
113- }
114-
115- for ( let thisVariant of toolVariants )
111+ for ( let thisVariant of opts . toolFilenames )
116112 {
117113 tl . debug ( `looking for tool variant ${ thisVariant } ` ) ;
118114
@@ -136,9 +132,29 @@ export function locateTool(tool: string | string[], opts?: LocateOptions) {
136132 tl . debug ( "not found" ) ;
137133 }
138134
139- if ( ! opts . optional ) {
140- throw new Error ( tl . loc ( "NGCommon_UnableToFindTool" , toolVariants [ 0 ] ) ) ;
135+ return null ;
136+ }
137+
138+ export function locateNuGetExe ( userNuGetExePath : string ) : string {
139+ if ( userNuGetExePath ) {
140+ tl . debug ( `using user-supplied NuGet path ${ userNuGetExePath } ` )
141+ tl . checkPath ( userNuGetExePath , 'NuGet' ) ;
142+ return userNuGetExePath ;
143+ }
144+
145+ var toolPath = locateTool ( 'NuGet' , {
146+ fallbackToSystemPath : os . platform ( ) !== 'win32' ,
147+ toolFilenames : [ 'nuget.exe' , 'NuGet.exe' , 'nuget' , 'NuGet' ]
148+ } ) ;
149+
150+
151+ if ( ! toolPath ) {
152+ throw new Error ( tl . loc ( "NGCommon_UnableToFindTool" , 'NuGet' ) ) ;
141153 }
142154
143- return null ;
155+ return toolPath ;
156+ }
157+
158+ export function locateCredentialProvider ( ) : string {
159+ return locateTool ( 'CredentialProvider.TeamBuild.exe' ) ;
144160}
0 commit comments