@@ -7,12 +7,13 @@ namespace CSharpier.Cli;
77
88internal static class HasMismatchedCliAndMsBuildVersions
99{
10- public static bool Check ( string directoryName , IFileSystem fileSystem , ILogger logger )
10+ public static async Task < bool > Check (
11+ string directoryName ,
12+ IFileSystem fileSystem ,
13+ ILogger logger ,
14+ CancellationToken cancellationToken
15+ )
1116 {
12- var csProjPaths = fileSystem
13- . Directory . EnumerateFiles ( directoryName , "*.csproj" , SearchOption . AllDirectories )
14- . ToArray ( ) ;
15-
1617 var versionOfDotnetTool = typeof ( CommandLineFormatter )
1718 . Assembly . GetName ( )
1819 . Version ! . ToString ( 3 ) ;
@@ -51,14 +52,38 @@ public static bool Check(string directoryName, IFileSystem fileSystem, ILogger l
5152 return null ;
5253 }
5354
54- foreach ( var pathToCsProj in csProjPaths )
55+ IEnumerable < string > EnumerateFiles ( string directory )
56+ {
57+ // using optionsProvider is slower so just hard coding the ones that could cause performance issues
58+ if ( fileSystem . Path . GetDirectoryName ( directory ) is "node_modules" or ".git" )
59+ {
60+ yield break ;
61+ }
62+
63+ foreach ( var file in fileSystem . Directory . EnumerateFiles ( directory , "*.csproj" ) )
64+ {
65+ yield return file ;
66+ }
67+
68+ foreach ( var subDirectory in fileSystem . Directory . EnumerateDirectories ( directory ) )
69+ {
70+ foreach ( var file in EnumerateFiles ( subDirectory ) )
71+ {
72+ yield return file ;
73+ }
74+ }
75+ }
76+
77+ foreach ( var pathToCsProj in EnumerateFiles ( directoryName ) )
5578 {
5679 // this could potentially use the Microsoft.Build.Evaluation class, but that was
5780 // throwing exceptions trying to load project files with "The SDK 'Microsoft.NET.Sdk' specified could not be found."
5881 XElement csProjXElement ;
5982 try
6083 {
61- csProjXElement = XElement . Parse ( fileSystem . File . ReadAllText ( pathToCsProj ) ) ;
84+ csProjXElement = XElement . Parse (
85+ await fileSystem . File . ReadAllTextAsync ( pathToCsProj , cancellationToken )
86+ ) ;
6287 }
6388 catch ( Exception ex )
6489 {
0 commit comments