/// <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));
        }
        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);
        }
Esempio n. 3
0
        public PackageSearchItem(Project project, PackageReaderBase reader)
        {
            Identity = reader.GetIdentity();
            Id       = Identity.Id;
            Title    = reader.NuspecReader.GetTitle();
            if (string.IsNullOrEmpty(Title))
            {
                Title = Id;
            }
            IsInstalled = isPackageIdInProjectDependencies(project, Id);

            InstalledVersion = "";
            // Find installed version !
            var LocalVersion = NuGetPackageManager.Instance.getLocal(Id);

            CanInstall = false;
            if (LocalVersion != null)
            {
                if (project.dependencies != null)
                {
                    foreach (JProperty jp in (JToken)project.dependencies)
                    {
                        if (jp.Name == Id)
                        {
                            InstalledVersion = (string)jp.Value;
                            CanInstall       = true;
                        }
                    }
                }
                if (string.IsNullOrEmpty(InstalledVersion))
                {
                    InstalledVersion = LocalVersion.Identity.Version.ToString();
                }
                SelectedVersion = InstalledVersion;
            }
            NotifyPropertyChanged("InstalledVersion");

            LicenseUrl   = reader.NuspecReader.GetLicenseUrl();
            ProjectUrl   = reader.NuspecReader.GetProjectUrl();
            Tags         = reader.NuspecReader.GetTags();
            Description  = reader.NuspecReader.GetDescription();
            IconUrl      = reader.NuspecReader.GetIconUrl();
            Authors      = reader.NuspecReader.GetAuthors();
            Dependencies = reader.GetPackageDependencies().ToList();
        }