/// <summary>
        /// Get an InteractivePackage with populated assembly references from a restored NuGet package.
        /// </summary>
        /// <param name="inputPackages">Input to RestorePackagesAsync, used to ensure the returned package
        /// has the same SupportedVersionRange as the requested package, and to determine if this is a
        /// user-specified package or a dependency.</param>
        static InteractivePackage GetInteractivePackageFromReader(
            PackageReaderBase packageReader,
            InteractiveNuGetProject project,
            IEnumerable <InteractivePackage> inputPackages)
        {
            ImmutableList <FilePath> assemblyReferences = null;
            var fx = project.TargetFramework;
            var packageIdentity = packageReader.GetIdentity();

            if (packageReader
                .GetSupportedFrameworks()
                .Any(f => DefaultCompatibilityProvider.Instance.IsCompatible(fx, f)))
            {
                assemblyReferences =
                    project.GetPackageAssemblyReferences(packageReader, packageIdentity);
            }

            var originalInputPackage = inputPackages.FirstOrDefault(
                p => PackageIdComparer.Equals(p.Identity, packageIdentity));

            // Persist original VersionRange to what gets in the installed package list so that
            // the same original version range string gets written to the manifest on save
            return(new InteractivePackage(
                       packageIdentity,
                       isExplicit: originalInputPackage?.IsExplicit == true,
                       assemblyReferences: assemblyReferences,
                       supportedVersionRange: originalInputPackage?.SupportedVersionRange));
        }
Пример #2
0
        /// <summary>
        /// Возвращает список совместимых элементов.
        /// </summary>
        /// <param name="reader">Интерфейс для чтения метаданных пакета.</param>
        /// <param name="items">Список элементов для выборки.</param>
        /// <param name="targetFramework">Версия совместимого фреймворка.</param>
        /// <param name="compatibilityProvider">Провайдер для проверки совместимости фреймворков.</param>
        private static FrameworkSpecificGroup GetCompatibleItems(PackageReaderBase reader,
                                                                 IList <FrameworkSpecificGroup> items,
                                                                 NuGetFramework targetFramework,
                                                                 IFrameworkCompatibilityProvider compatibilityProvider)
        {
            // Из пакета выбираются файлы с TargetFramework, который
            // является наиболее новым и совместимым с указанным

            var compatibleItems = items
                                  .OrderByDescending(i => i.TargetFramework, NuGetFrameworkComparer)
                                  .FirstOrDefault(i => NuGetFrameworkComparer.Compare(i.TargetFramework, targetFramework) <= 0 &&
                                                  compatibilityProvider.IsCompatible(targetFramework, i.TargetFramework));

            if (compatibleItems == null)
            {
                var portableFramework = reader.GetSupportedFrameworks()
                                        .FirstOrDefault(i => string.Equals(i.Framework, FrameworkConstants.FrameworkIdentifiers.NetPlatform, StringComparison.OrdinalIgnoreCase));

                if (portableFramework != null && compatibilityProvider.IsCompatible(targetFramework, portableFramework))
                {
                    compatibleItems = items.FirstOrDefault(i => NuGetFrameworkComparer.Compare(i.TargetFramework, portableFramework) == 0);
                }
            }

            if (compatibleItems == null)
            {
                // TODO Update Nuget packages, add .NETStandard compability
                compatibleItems = items.FirstOrDefault(i => i.TargetFramework.DotNetFrameworkName.Contains(FrameworkConstants.FrameworkIdentifiers.NetStandard));
            }

            return(compatibleItems);
        }
Пример #3
0
        public static IReadOnlyDictionary <NuGetFramework, IReadOnlyList <TypeChanges> > ComparePackageTypes(PackageReaderBase package1, PackageReaderBase package2, out NuGetVersion suggestedVersion)
        {
            if (package1 == null)
            {
                throw new ArgumentNullException(nameof(package1));
            }
            if (package2 == null)
            {
                throw new ArgumentNullException(nameof(package2));
            }

            var frameworkChanges = new Dictionary <NuGetFramework, IReadOnlyList <TypeChanges> >();

            foreach (var targetFramework in package1.GetSupportedFrameworks())
            {
                var typeChanges = new List <TypeChanges>();
                frameworkChanges.Add(targetFramework, typeChanges.AsReadOnly());
                var dlls1 = package1.GetAssemblyReferences(targetFramework).ToList();
                var dlls2 = package2.GetAssemblyReferences(targetFramework).ToList();
                if (dlls1.Count != 0 && dlls2.Count == 0)
                {
                    typeChanges.Add(new TypeChanges(null, new[] { Change.NonBreaking("Framework support removed: {0}", targetFramework) }.ToList().AsReadOnly()));
                    continue;
                }
                var changes = new List <Change>();
                foreach (var file1 in dlls1)
                {
                    if (dlls2.Contains(file1))
                    {
                        typeChanges.AddRange(FindChanges(package1.GetStream(file1), package2.GetStream(file1)));
                    }
                    else
                    {
                        changes.Add(Change.Breaking("Assembly removed: {0}", file1));
                    }
                }
                if (changes.Count != 0)
                {
                    typeChanges.Add(new TypeChanges(null, changes.AsReadOnly()));
                }
            }

            suggestedVersion = SuggestVersion(package1.GetIdentity().Version, frameworkChanges.SelectMany(x => x.Value.SelectMany(y => y.Changes)).ToList());

            return(frameworkChanges);
        }