@@ -712,104 +712,14 @@ public virtual IEnumerable<NuGetFramework> GetSupportedFrameworks(PackageArchive
712712 return package . GetSupportedFrameworks ( ) ;
713713 }
714714
715- /// <summary>
716- /// This method combines the logic used in restore operations to make a determination about the TFM supported by the package.
717- /// We have curated a set of compatibility requirements for our needs in NuGet.org. The client logic can be found here:
718- /// https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs#L252-L294
719- /// https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs#L439-L442
720- /// ...and our combination of these elements is below.
721- /// The logic is essentially this:
722- /// - Determine whether we're looking at a tools package. In this case we will use tools "pattern sets" (collections of file patterns
723- /// defined in <see cref="ManagedCodeConventions" />) to assess which frameworks are targeted by the package.
724- /// - If this isn't a tools package, we look for build-time, runtime, content and resource file patterns
725- /// For added details on the various cases, see unit tests targeting this method.
726- /// </summary>
727715 public virtual IEnumerable < NuGetFramework > GetSupportedFrameworks ( NuspecReader nuspecReader , IList < string > packageFiles )
728716 {
729- var supportedTFMs = Enumerable . Empty < NuGetFramework > ( ) ;
730- if ( packageFiles != null && packageFiles . Any ( ) && nuspecReader != null )
731- {
732- // Setup content items for analysis
733- var items = new ContentItemCollection ( ) ;
734- items . Load ( packageFiles ) ;
735- var runtimeGraph = new RuntimeGraph ( ) ;
736- var conventions = new ManagedCodeConventions ( runtimeGraph ) ;
737-
738- // Let's test for tools packages first--they're a special case
739- var groups = Enumerable . Empty < ContentItemGroup > ( ) ;
740- var packageTypes = nuspecReader . GetPackageTypes ( ) ;
741- if ( packageTypes . Count == 1 && ( packageTypes [ 0 ] == PackageType . DotnetTool ||
742- packageTypes [ 0 ] == PackageType . DotnetCliTool ) )
743- {
744- // Only a package that is a tool package (and nothing else) will be matched against tools pattern set
745- groups = items . FindItemGroups ( conventions . Patterns . ToolsAssemblies ) ;
746- }
747- else
748- {
749- // Gather together a list of pattern sets indicating the kinds of packages we wish to evaluate
750- var patterns = new [ ]
751- {
752- conventions . Patterns . CompileRefAssemblies ,
753- conventions . Patterns . CompileLibAssemblies ,
754- conventions . Patterns . RuntimeAssemblies ,
755- conventions . Patterns . ContentFiles ,
756- conventions . Patterns . ResourceAssemblies ,
757- } ;
758-
759- // Add MSBuild to this list, but we need to ensure we have package assets before they make the cut.
760- // A series of files in the right places won't matter if there's no {id}.props|targets.
761- var msbuildPatterns = new [ ]
762- {
763- conventions . Patterns . MSBuildFiles ,
764- conventions . Patterns . MSBuildMultiTargetingFiles ,
765- } ;
766-
767- // We'll create a set of "groups" --these are content items which satisfy file pattern sets
768- var standardGroups = patterns
769- . SelectMany ( p => items . FindItemGroups ( p ) ) ;
770-
771- // Filter out MSBuild assets that don't match the package ID and append to groups we already have
772- var packageId = nuspecReader . GetId ( ) ;
773- var msbuildGroups = msbuildPatterns
774- . SelectMany ( p => items . FindItemGroups ( p ) )
775- . Where ( g => HasBuildItemsForPackageId ( g . Items , packageId ) ) ;
776- groups = standardGroups . Concat ( msbuildGroups ) ;
777- }
778-
779- // Now that we have a collection of groups which have made it through the pattern set filter, let's transform them into TFMs
780- supportedTFMs = groups
781- . SelectMany ( p => p . Properties )
782- . Where ( pair => pair . Key == ManagedCodeConventions . PropertyNames . TargetFrameworkMoniker )
783- . Select ( pair => pair . Value )
784- . Cast < NuGetFramework > ( )
785- . Distinct ( ) ;
786- }
787-
788- return supportedTFMs ;
789- }
790-
791- private static bool HasBuildItemsForPackageId ( IEnumerable < ContentItem > items , string packageId )
792- {
793- foreach ( var item in items )
717+ if ( nuspecReader != null )
794718 {
795- var fileName = Path . GetFileName ( item . Path ) ;
796- if ( fileName == PackagingCoreConstants . EmptyFolder )
797- {
798- return true ;
799- }
800-
801- if ( $ "{ packageId } .props". Equals ( fileName , StringComparison . OrdinalIgnoreCase ) )
802- {
803- return true ;
804- }
805-
806- if ( $ "{ packageId } .targets". Equals ( fileName , StringComparison . OrdinalIgnoreCase ) )
807- {
808- return true ;
809- }
719+ return AssetFrameworkHelper . GetAssetFrameworks ( nuspecReader . GetId ( ) , nuspecReader . GetPackageTypes ( ) , packageFiles ) ;
810720 }
811721
812- return false ;
722+ return Enumerable . Empty < NuGetFramework > ( ) ;
813723 }
814724
815725 private static EmbeddedLicenseFileType GetEmbeddedLicenseType ( PackageMetadata packageMetadata )
0 commit comments