@@ -340,6 +340,52 @@ private static string GetGroup(ReadOnlySpan<char> input, ValueMatch valueMatch,
340
340
return match . Slice ( quoteIndex1 + 1 , quoteIndex2 ) . ToString ( ) . ToLowerInvariant ( ) ;
341
341
}
342
342
343
+ private static bool IsGroupMatch ( ReadOnlySpan < char > line , Regex regex , string groupPrefix , string value )
344
+ {
345
+ foreach ( var valueMatch in regex . EnumerateMatches ( line ) )
346
+ {
347
+ // We can't get the group from the ValueMatch, so doing it manually:
348
+ if ( GetGroup ( line , valueMatch , groupPrefix ) == value )
349
+ {
350
+ return true ;
351
+ }
352
+ }
353
+ return false ;
354
+ }
355
+
356
+ /// <summary>
357
+ /// Returns true if the given project uses the ASP.NET components.
358
+ /// The following heuristic is used to decide, if ASP.NET is used:
359
+ /// If any file in the project contains either of (this will most like be a .csproj file)
360
+ /// <Project Sdk="Microsoft.NET.Sdk.Web" ...
361
+ /// <FrameworkReference Include="Microsoft.AspNetCore.App" ...
362
+ /// </summary>
363
+ private bool UseAspNetDlls ( )
364
+ {
365
+ var allFiles = GetFiles ( "*.*" ) ;
366
+ foreach ( var file in allFiles )
367
+ {
368
+ try
369
+ {
370
+ using var sr = new StreamReader ( file ) ;
371
+ ReadOnlySpan < char > line ;
372
+ while ( ( line = sr . ReadLine ( ) ) != null )
373
+ {
374
+ if ( IsGroupMatch ( line , ProjectSdk ( ) , "Sdk" , "Microsoft.NET.Sdk.Web" ) ||
375
+ IsGroupMatch ( line , FrameworkReference ( ) , "Include" , "Microsoft.AspNetCore.App" ) )
376
+ {
377
+ return true ;
378
+ }
379
+ }
380
+ }
381
+ catch ( Exception ex )
382
+ {
383
+ progressMonitor . FailedToReadFile ( file , ex ) ;
384
+ }
385
+ }
386
+ return false ;
387
+ }
388
+
343
389
private void DownloadMissingPackages ( IEnumerable < string > restoreTargets )
344
390
{
345
391
var alreadyDownloadedPackages = Directory . GetDirectories ( packageDirectory . DirInfo . FullName ) . Select ( d => Path . GetFileName ( d ) . ToLowerInvariant ( ) ) . ToHashSet ( ) ;
0 commit comments