@@ -38,40 +38,34 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
3838 WarnAboutAmbiguousConfigFileSelection ( workingDirectory , projectRootDirectory ) ;
3939 }
4040
41- public string ? GetConfigurationFile ( string ? directory )
41+ public string ? GetConfigurationFile ( string ? directoryPath )
4242 {
43- // If configuration file overriden and its exists, return it
44- if ( ! string . IsNullOrWhiteSpace ( this . ConfigurationFile ) &&
45- PathHelper . IsPathRooted ( this . ConfigurationFile ) &&
46- fileSystem . File . Exists ( this . ConfigurationFile ) )
47- {
48- return this . ConfigurationFile ;
49- }
50-
51- if ( directory is null ) return null ;
43+ string [ ] configurationFilePaths = string . IsNullOrWhiteSpace ( this . ConfigurationFile )
44+ ? this . SupportedConfigFileNames : [ this . ConfigurationFile , .. this . SupportedConfigFileNames ] ;
5245
53- string [ ] candidates = ! string . IsNullOrWhiteSpace ( this . ConfigurationFile )
54- ? [ this . ConfigurationFile , .. this . SupportedConfigFileNames ]
55- : this . SupportedConfigFileNames ;
56-
57- foreach ( var fileName in candidates )
46+ foreach ( var item in configurationFilePaths )
5847 {
59- this . log . Debug ( $ "Trying to find configuration file { fileName } at '{ directory } '") ;
60- if ( directory != null && fileSystem . Directory . Exists ( directory ) )
61- {
62- var files = fileSystem . Directory . GetFiles ( directory ) ;
48+ this . log . Debug ( $ "Trying to find configuration file { item } at '{ directoryPath } '") ;
6349
64- var matchingFile = files . FirstOrDefault ( file =>
65- string . Equals ( fileSystem . Path . GetFileName ( file ) , fileName , StringComparison . OrdinalIgnoreCase ) ) ;
66-
67- if ( matchingFile != null )
50+ var configurationFilePath = item ;
51+ if ( ! PathHelper . IsPathRooted ( configurationFilePath ) )
52+ {
53+ if ( string . IsNullOrEmpty ( directoryPath ) )
6854 {
69- this . log . Info ( $ "Found configuration file at '{ matchingFile } '") ;
70- return matchingFile ;
55+ throw new WarningException (
56+ $ "The configuration file '{ configurationFilePath } ' is relative and no directory path known."
57+ ) ;
7158 }
59+ configurationFilePath = Path . Combine ( directoryPath , configurationFilePath ) ;
60+ }
61+
62+ if ( fileSystem . File . Exists ( configurationFilePath ) )
63+ {
64+ this . log . Info ( $ "Found configuration file at '{ configurationFilePath } '") ;
65+ return configurationFilePath ;
7266 }
7367
74- this . log . Debug ( $ "Configuration file { fileName } not found at '{ directory } '") ;
68+ this . log . Debug ( $ "Configuration file { configurationFilePath } not found at '{ directoryPath } '") ;
7569 }
7670
7771 return null ;
0 commit comments