@@ -157,23 +157,35 @@ private static bool IsGroupMatch(ReadOnlySpan<char> line, Regex regex, string gr
157157 return false ;
158158 }
159159
160+ private void AddPackageReference ( ReadOnlySpan < char > line , string groupName , Func < Regex > regex )
161+ {
162+ foreach ( var valueMatch in regex ( ) . EnumerateMatches ( line ) )
163+ {
164+ // We can't get the group from the ValueMatch, so doing it manually:
165+ var packageName = GetGroup ( line , valueMatch , groupName ) . ToLowerInvariant ( ) ;
166+ if ( ! string . IsNullOrEmpty ( packageName ) )
167+ {
168+ allPackages . Add ( packageName ) ;
169+ }
170+ }
171+ }
172+
160173 private void DoInitialize ( )
161174 {
162175 foreach ( var file in files )
163176 {
164177 try
165178 {
179+ var isPackagesConfig = file . EndsWith ( "packages.config" , StringComparison . OrdinalIgnoreCase ) ;
180+
166181 foreach ( ReadOnlySpan < char > line in unsafeFileReader . ReadLines ( file ) )
167182 {
168183 // Find all the packages.
169- foreach ( var valueMatch in PackageReference ( ) . EnumerateMatches ( line ) )
184+ AddPackageReference ( line , "Include" , PackageReference ) ;
185+
186+ if ( isPackagesConfig )
170187 {
171- // We can't get the group from the ValueMatch, so doing it manually:
172- var packageName = GetGroup ( line , valueMatch , "Include" ) . ToLowerInvariant ( ) ;
173- if ( ! string . IsNullOrEmpty ( packageName ) )
174- {
175- allPackages . Add ( packageName ) ;
176- }
188+ AddPackageReference ( line , "id" , LegacyPackageReference ) ;
177189 }
178190
179191 // Determine if ASP.NET is used.
@@ -223,6 +235,9 @@ private void DoInitialize()
223235 [ GeneratedRegex ( "(?<!<!--.*)<PackageReference.*\\ sInclude=\" (.*?)\" .*/?>" , RegexOptions . IgnoreCase | RegexOptions . Compiled | RegexOptions . Singleline ) ]
224236 private static partial Regex PackageReference ( ) ;
225237
238+ [ GeneratedRegex ( "(?<!<!--.*)<package.*\\ sid=\" (.*?)\" .*/?>" , RegexOptions . IgnoreCase | RegexOptions . Compiled | RegexOptions . Singleline ) ]
239+ private static partial Regex LegacyPackageReference ( ) ;
240+
226241 [ GeneratedRegex ( "(?<!<!--.*)<FrameworkReference.*\\ sInclude=\" (.*?)\" .*/?>" , RegexOptions . IgnoreCase | RegexOptions . Compiled | RegexOptions . Singleline ) ]
227242 private static partial Regex FrameworkReference ( ) ;
228243
0 commit comments