@@ -40,35 +40,46 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
4040
4141 public string ? GetConfigurationFile ( string ? directoryPath )
4242 {
43- string [ ] configurationFilePaths = string . IsNullOrWhiteSpace ( this . ConfigurationFile )
44- ? this . SupportedConfigFileNames : [ this . ConfigurationFile , .. this . SupportedConfigFileNames ] ;
43+ string ? customConfigurationFile = GetCustomConfigurationFilePathIfEligable ( directoryPath ) ;
44+ if ( ! string . IsNullOrWhiteSpace ( customConfigurationFile ) )
45+ {
46+ return customConfigurationFile ;
47+ }
4548
46- foreach ( var item in configurationFilePaths )
49+ if ( string . IsNullOrWhiteSpace ( directoryPath ) || ! fileSystem . Directory . Exists ( directoryPath ) )
4750 {
48- this . log . Debug ( $ "Trying to find configuration file { item } at '{ directoryPath } '") ;
51+ return null ;
52+ }
4953
50- string configurationFilePath ;
51- if ( ! PathHelper . IsPathRooted ( item ) )
54+ string [ ] files = fileSystem . Directory . GetFiles ( directoryPath ) ;
55+ foreach ( var fileName in this . SupportedConfigFileNames )
56+ {
57+ this . log . Debug ( $ "Trying to find configuration file { fileName } at '{ directoryPath } '") ;
58+ string ? matchingFile = files . FirstOrDefault ( file => string . Equals ( PathHelper . GetFileName ( file ) , fileName , StringComparison . OrdinalIgnoreCase ) ) ;
59+ if ( matchingFile != null )
5260 {
53- if ( string . IsNullOrEmpty ( directoryPath ) )
54- {
55- this . log . Info ( $ "The configuration file '{ item } ' is relative and no directory path known.") ;
56- continue ;
57- }
58- configurationFilePath = Path . Combine ( directoryPath , item ) ;
61+ this . log . Info ( $ "Found configuration file at '{ matchingFile } '") ;
62+ return matchingFile ;
5963 }
60- else
64+ }
65+
66+ return null ;
67+ }
68+
69+ private string ? GetCustomConfigurationFilePathIfEligable ( string ? directoryPath )
70+ {
71+ if ( ! string . IsNullOrWhiteSpace ( this . ConfigurationFile ) )
72+ {
73+ string configurationFilePath = this . ConfigurationFile ;
74+ if ( ! string . IsNullOrWhiteSpace ( directoryPath ) )
6175 {
62- configurationFilePath = item ;
76+ configurationFilePath = Path . Combine ( directoryPath , this . ConfigurationFile ) ;
6377 }
6478
6579 if ( fileSystem . File . Exists ( configurationFilePath ) )
6680 {
67- this . log . Info ( $ "Found configuration file at '{ configurationFilePath } '") ;
6881 return configurationFilePath ;
6982 }
70-
71- this . log . Debug ( $ "Configuration file { configurationFilePath } not found at '{ directoryPath } '") ;
7283 }
7384
7485 return null ;
0 commit comments