@@ -38,32 +38,48 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
38
38
WarnAboutAmbiguousConfigFileSelection ( workingDirectory , projectRootDirectory ) ;
39
39
}
40
40
41
- public string ? GetConfigurationFile ( string ? directory )
41
+ public string ? GetConfigurationFile ( string ? directoryPath )
42
42
{
43
- if ( directory is null ) return null ;
43
+ string ? customConfigurationFile = GetCustomConfigurationFilePathIfEligable ( directoryPath ) ;
44
+ if ( ! string . IsNullOrWhiteSpace ( customConfigurationFile ) )
45
+ {
46
+ return customConfigurationFile ;
47
+ }
44
48
45
- string [ ] candidates = ! string . IsNullOrWhiteSpace ( this . ConfigurationFile )
46
- ? [ this . ConfigurationFile , .. this . SupportedConfigFileNames ]
47
- : this . SupportedConfigFileNames ;
49
+ if ( string . IsNullOrWhiteSpace ( directoryPath ) || ! fileSystem . Directory . Exists ( directoryPath ) )
50
+ {
51
+ return null ;
52
+ }
48
53
49
- foreach ( var fileName in candidates )
54
+ string [ ] files = fileSystem . Directory . GetFiles ( directoryPath ) ;
55
+ foreach ( var fileName in this . SupportedConfigFileNames )
50
56
{
51
- this . log . Debug ( $ "Trying to find configuration file { fileName } at '{ directory } '") ;
52
- if ( directory != null && fileSystem . Directory . Exists ( directory ) )
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 )
53
60
{
54
- var files = fileSystem . Directory . GetFiles ( directory ) ;
61
+ this . log . Info ( $ "Found configuration file at '{ matchingFile } '") ;
62
+ return matchingFile ;
63
+ }
64
+ }
55
65
56
- var matchingFile = files . FirstOrDefault ( file =>
57
- string . Equals ( fileSystem . Path . GetFileName ( file ) , fileName , StringComparison . OrdinalIgnoreCase ) ) ;
66
+ return null ;
67
+ }
58
68
59
- if ( matchingFile != null )
60
- {
61
- this . log . Info ( $ "Found configuration file at '{ matchingFile } '") ;
62
- return matchingFile ;
63
- }
69
+ private string ? GetCustomConfigurationFilePathIfEligable ( string ? directoryPath )
70
+ {
71
+ if ( ! string . IsNullOrWhiteSpace ( this . ConfigurationFile ) )
72
+ {
73
+ string configurationFilePath = this . ConfigurationFile ;
74
+ if ( ! string . IsNullOrWhiteSpace ( directoryPath ) )
75
+ {
76
+ configurationFilePath = Path . Combine ( directoryPath , this . ConfigurationFile ) ;
64
77
}
65
78
66
- this . log . Debug ( $ "Configuration file { fileName } not found at '{ directory } '") ;
79
+ if ( fileSystem . File . Exists ( configurationFilePath ) )
80
+ {
81
+ return configurationFilePath ;
82
+ }
67
83
}
68
84
69
85
return null ;
0 commit comments