public IEnumerable <string> Filter(IEnumerable <string> assemblyPaths, string targetFrameworkStr)
        {
            NuGetFramework targetFramework;

            if (!TryParseTargetFramework(targetFrameworkStr, out targetFramework))
            {
                throw new ArgumentException("Invalid target framework value.");
            }

            var compatibilityProvider = new CompatibilityProvider(new DefaultFrameworkNameProvider());

            var result = new LinkedList <string>();

            foreach (var assemblyPath in assemblyPaths)
            {
                NuGetFramework framework;
                if (!TryGetTargetFrameworkFromPath(assemblyPath, out framework))
                {
                    continue;
                }

                var isCompatible = compatibilityProvider.IsCompatible(targetFramework, framework);
                if (!isCompatible)
                {
                    var expandedFrameworks = ExpandTargetFramework(framework);
                    foreach (var expandedFramework in expandedFrameworks)
                    {
                        isCompatible = compatibilityProvider.IsCompatible(targetFramework, expandedFramework);
                        if (isCompatible)
                        {
                            break;
                        }
                    }
                }

                if (isCompatible)
                {
                    result.AddLast(assemblyPath);
                }
            }

            return(result);
        }
Esempio n. 2
0
        private void HandleRuntimeDlls(PackageIdentity packageIdentity, List <ZipArchiveEntry> zipArchiveEntries)
        {
            var runtimeEntries = zipArchiveEntries
                                 .Where(e => string.Equals(e.FullName.Split('/')[0], "runtimes", StringComparison.InvariantCultureIgnoreCase))
                                 .Select(e => new { Rid = e.FullName.Split('/')[1], Entry = e }).ToList();

            foreach (var runtime in runtimeEntries)
            {
                var runtimeDll = new RunTimeDll()
                {
                    FileName         = runtime.Entry.Name,
                    FullFilePath     = Path.Combine(_root, packageIdentity.ToString(), runtime.Entry.FullName),
                    RelativeFilePath = Path.Combine(packageIdentity.ToString(), runtime.Entry.FullName),
                    PackageIdentity  = packageIdentity.Id,
                };

                var runtimeDllDetails = ParseRuntimeDllDetails(runtime.Entry.FullName);
                runtimeDll.RID                      = runtimeDllDetails.Rid;
                runtimeDll.TargetFramework          = runtimeDllDetails.Target;
                runtimeDll.TargetFrameworkShortName = runtimeDllDetails.TargetShortName;
                runtimeDll.TargetVersion            = runtimeDllDetails.TargetVersion;

                RuntimeDlls.Add(runtimeDll);
            }

            var supportedRunTimeDlls = RuntimeDlls.Where(x => SupportedRids.Contains(x.RID)).ToList();

            var runtimeLibFiles = supportedRunTimeDlls.Where(x => x.IsLib).GroupBy(x => x.FileName).ToList();

            foreach (var fileGroup in runtimeLibFiles)
            {
                var targetFrameworks = fileGroup.Select(x =>
                                                        NuGetFramework.ParseFrameworkName(x.TargetFramework, new DefaultFrameworkNameProvider()))
                                       .ToList();

                var compatibleFrameworks =
                    targetFrameworks.Where(x => _compProvider.IsCompatible(_targetFramework, x)).ToList();

                foreach (var runTimeDll in fileGroup)
                {
                    if (compatibleFrameworks.Any(x => string.Equals(x.DotNetFrameworkName, runTimeDll.TargetFramework)))
                    {
                        runTimeDll.IsSupported = true;
                    }
                }

                var mostMatching = _reducer.GetNearest(_targetFramework, targetFrameworks);

                if (mostMatching == null)
                {
                    continue;
                }

                foreach (var runTimeDll in fileGroup)
                {
                    if (string.Equals(runTimeDll.TargetFramework, mostMatching.DotNetFrameworkName))
                    {
                        runTimeDll.IsRecommended = true;
                    }
                }
            }

            var runtimeNativeFiles = supportedRunTimeDlls.Where(x => x.IsNative).GroupBy(x => x.FileName).ToList();

            foreach (var fileGroup in runtimeNativeFiles)
            {
                foreach (var runTimeDll in fileGroup)
                {
                    runTimeDll.IsSupported = true;
                }

                // The Rids are already ordered from best match to the least matching
                var recommededFound = false;
                foreach (var supportedRid in SupportedRids)
                {
                    foreach (var runTimeDll in fileGroup)
                    {
                        if (string.Equals(runTimeDll.RID, supportedRid))
                        {
                            runTimeDll.IsRecommended = true;
                            recommededFound          = true;

                            break;
                        }

                        if (recommededFound)
                        {
                            break;
                        }
                    }
                }
            }
        }