Пример #1
0
        private void InitPackageUpgradeIssues(FolderNuGetProject folderNuGetProject, NuGetProjectUpgradeDependencyItem package, NuGetFramework framework)
        {
            _notFoundPackages = new HashSet <PackageIdentity>();
            var packageIdentity = new PackageIdentity(package.Id, NuGetVersion.Parse(package.Version));
            // Confirm package exists
            var packagePath = folderNuGetProject.GetInstalledPackageFilePath(packageIdentity);

            if (string.IsNullOrEmpty(packagePath))
            {
                HasIssues           = true;
                HasNotFoundPackages = true;
                _notFoundPackages.Add(packageIdentity);
                package.Issues.Add(PackagingLogMessage.CreateWarning(
                                       string.Format(CultureInfo.CurrentCulture, Resources.Upgrader_PackageNotFound, packageIdentity.Id),
                                       NuGetLogCode.NU5500));
            }
            else
            {
                using (var reader = new PackageArchiveReader(packagePath))
                {
                    var packageRules = RuleSet.PackagesConfigToPackageReferenceMigrationRuleSet;
                    var issues       = package.Issues;

                    foreach (var rule in packageRules)
                    {
                        var foundIssues = rule.Validate(reader).OrderBy(p => p.Code.ToString(), StringComparer.CurrentCulture);
                        if (foundIssues != null && foundIssues.Any())
                        {
                            HasIssues = true;
                        }
                        issues.AddRange(foundIssues);
                    }
                }
            }
        }
Пример #2
0
 /* The package will be installed as top level if :
  * 1) The package contains build, buildCrossTargeting, contentFiles or analyzers folder.
  * 2) The package has developmentDependency set to true.
  */
 private static void PromoteToTopLevelIfNeeded(PackageArchiveReader reader, NuGetProjectUpgradeDependencyItem item)
 {
     if (reader.GetDevelopmentDependency() ||
         reader.GetFiles(PackagingConstants.Folders.Build).Any() ||
         reader.GetFiles(PackagingConstants.Folders.BuildCrossTargeting).Any() ||
         reader.GetFiles(PackagingConstants.Folders.ContentFiles).Any() ||
         reader.GetFiles(PackagingConstants.Folders.Analyzers).Any())
     {
         item.InstallAsTopLevel = true;
     }
 }
Пример #3
0
        private static void InitPackageUpgradeIssues(
            string packagePath,
            NuGetProjectUpgradeDependencyItem package,
            HashSet <PackageIdentity> notFoundPackages,
            ref bool hasIssues)
        {
            var packageIdentity = new PackageIdentity(package.Id, NuGetVersion.Parse(package.Version));

            if (string.IsNullOrEmpty(packagePath))
            {
                hasIssues = true;
                notFoundPackages.Add(packageIdentity);
                package.Issues.Add(PackagingLogMessage.CreateWarning(
                                       string.Format(CultureInfo.CurrentCulture, Resources.Upgrader_PackageNotFound, packageIdentity.Id),
                                       NuGetLogCode.NU5500));
            }
            else
            {
                using (var reader = new PackageArchiveReader(packagePath))
                {
                    IEnumerable <IPackageRule>  packageRules = RuleSet.PackagesConfigToPackageReferenceMigrationRuleSet;
                    IList <PackagingLogMessage> issues       = package.Issues;

                    foreach (IPackageRule rule in packageRules)
                    {
                        IOrderedEnumerable <PackagingLogMessage> foundIssues = rule.Validate(reader)
                                                                               .OrderBy(p => p.Code.ToString(), StringComparer.CurrentCulture);

                        if (foundIssues != null && foundIssues.Any())
                        {
                            hasIssues = true;
                        }

                        issues.AddRange(foundIssues);
                    }

                    if (!package.InstallAsTopLevel)
                    {
                        PromoteToTopLevelIfNeeded(reader, package);
                    }
                }
            }
        }