Esempio n. 1
0
        public static ICollection<InstalledPackageReference> GetInstalledPackageReferences(PackageReferenceFile configFile, bool requireVersion)
        {
            if (configFile == null)
            {
                throw new ArgumentNullException("configFile");
            }

            var packageReferences = configFile.GetPackageReferences(requireVersion);
            foreach (var package in packageReferences)
            {
                // GetPackageReferences returns all records without validating values. We'll throw if we encounter packages
                // with malformed ids / Versions.
                if (String.IsNullOrEmpty(package.Id))
                {
                    throw new InvalidDataException(
                        String.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("InstallCommandInvalidPackageReference"), 
                        configFile.FullPath));
                }
                if (requireVersion && (package.Version == null))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("InstallCommandPackageReferenceInvalidVersion"), package.Id));
                }
            }

            return packageReferences.Select(pr => CoreConverters.SafeToInstalledPackageReference(pr)).ToList();
        }
Esempio n. 2
0
        public IEnumerable<string> CreatePackageFile()
        {
            var packagesFile = Path.Combine(_fileSystem.CurrentDirectory, Constants.PackagesFile);
            var packageReferenceFile = new PackageReferenceFile(packagesFile);

            var packagesFolder = Path.Combine(_fileSystem.CurrentDirectory, Constants.PackagesFolder);
            var repository = new LocalPackageRepository(packagesFolder);

            var newestPackages = repository.GetPackages().GroupBy(p => p.Id)
                .Select(g => g.OrderByDescending(p => p.Version).FirstOrDefault());

            foreach (var package in newestPackages)
            {
                var newestFramework = GetNewestSupportedFramework(package);
                packageReferenceFile.AddEntry(package.Id, package.Version, newestFramework);

                if (newestFramework == null)
                {
                    yield return string.Format("{0}, Version {1}", package.Id, package.Version);
                }
                else
                {
                    yield return string.Format("{0}, Version {1}, .NET {2}", package.Id, package.Version, newestFramework.Version);
                }
            }
        }
Esempio n. 3
0
 public static PackageReferenceFile CreateFromProject(string projectFileFullPath)
 {
     var fileSystem = new PhysicalFileSystem(Path.GetDirectoryName(projectFileFullPath));
     string projectName = Path.GetFileNameWithoutExtension(projectFileFullPath);
     var file = new PackageReferenceFile(fileSystem, Constants.PackageReferenceFile, projectName);
     return file;
 }
Esempio n. 4
0
        public static ICollection <PackageReference> GetPackageReferences(PackageReferenceFile file, string fileName, bool requireVersion)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            var packageReferences = file.GetPackageReferences(requireVersion).ToList();

            foreach (var package in packageReferences)
            {
                // GetPackageReferences returns all records without validating values. We'll throw if we encounter packages
                // with malformed ids / Versions.
                if (String.IsNullOrEmpty(package.Id))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandInvalidPackageReference, fileName));
                }
                if (requireVersion && (package.Version == null))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, package.Id));
                }
            }

            return(packageReferences);
        }
        public static PackageReferenceFile CreateFromProject(string projectFileFullPath)
        {
            var    fileSystem  = new PhysicalFileSystem(Path.GetDirectoryName(projectFileFullPath));
            string projectName = Path.GetFileNameWithoutExtension(projectFileFullPath);
            var    file        = new PackageReferenceFile(fileSystem, Constants.PackageReferenceFile, projectName);

            return(file);
        }
        public SharedPackageRepository(IPackagePathResolver resolver, IFileSystem fileSystem, IFileSystem configSettingsFileSystem)
            : base(resolver, fileSystem)
        {
            if (configSettingsFileSystem == null)
            {
                throw new ArgumentNullException("configSettingsFileSystem");
            }

            _packageReferenceFile = new PackageReferenceFile(configSettingsFileSystem, Constants.PackageReferenceFile);
        }
        public SharedPackageRepository(IPackagePathResolver resolver, IFileSystem fileSystem, IFileSystem configSettingsFileSystem)
            : base(resolver, fileSystem)
        {
            if (configSettingsFileSystem == null)
            {
                throw new ArgumentNullException("configSettingsFileSystem");
            }

            _packageReferenceFile = new PackageReferenceFile(configSettingsFileSystem, Constants.PackageReferenceFile);
        }
		public TestablePackageCompatibilityRunner (
			IDotNetProject project,
			IPackageManagementProgressMonitorFactory progressMonitorFactory,
			IPackageManagementEvents packageManagementEvents)
			: base (
				project,
				progressMonitorFactory,
				packageManagementEvents)
		{
			PackageReferenceFile = new PackageReferenceFile (FileSystem, "packages.config");
		}
Esempio n. 9
0
 public PackageReferenceRepository(IFileSystem fileSystem, string projectName, ISharedPackageRepository sourceRepository)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     if (sourceRepository == null)
     {
         throw new ArgumentNullException("sourceRepository");
     }
     this._packageReferenceFile = new PackageReferenceFile(fileSystem, Constants.PackageReferenceFile, projectName);
     this.SourceRepository      = sourceRepository;
 }
Esempio n. 10
0
 public PackageReferenceRepository(string configFilePath, ISharedPackageRepository sourceRepository)
 {
     if (string.IsNullOrEmpty(configFilePath))
     {
         throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "configFilePath");
     }
     if (sourceRepository == null)
     {
         throw new ArgumentNullException("sourceRepository");
     }
     this._packageReferenceFile = new PackageReferenceFile(configFilePath);
     this.SourceRepository      = sourceRepository;
 }
 public PackageReferenceRepository(IFileSystem fileSystem, ISharedPackageRepository sourceRepository)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     if (sourceRepository == null)
     {
         throw new ArgumentNullException("sourceRepository");
     }
     _packageReferenceFile = new PackageReferenceFile(fileSystem, Constants.PackageReferenceFile);
     _fullPath = fileSystem.GetFullPath(Constants.PackageReferenceFile);
     SourceRepository = sourceRepository;
 }
 public PackageReferenceRepository(IFileSystem fileSystem, ISharedPackageRepository sourceRepository)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     if (sourceRepository == null)
     {
         throw new ArgumentNullException("sourceRepository");
     }
     _packageReferenceFile = new PackageReferenceFile(fileSystem, PackageReferenceFile);
     _fullPath             = fileSystem.GetFullPath(PackageReferenceFile);
     SourceRepository      = sourceRepository;
 }
        /// <summary>
        /// Returns true if the package has a dependency on a project-level package.
        /// </summary>
        /// <param name="package">The package to check.</param>
        /// <returns>True if the package has a dependency on a project-level package.</returns>
        private bool HasProjectLevelPackageDependency(IPackage package)
        {
            var dependencies = package.DependencySets.SelectMany(p => p.Dependencies);

            if (dependencies.IsEmpty())
            {
                return(false);
            }

            HashSet <string> solutionLevelPackages = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            solutionLevelPackages.AddRange(
                PackageReferenceFile.GetPackageReferences().Select(packageReference => packageReference.Id));

            return(dependencies.Any(dependency => !solutionLevelPackages.Contains(dependency.Id)));
        }
Esempio n. 14
0
        public IEnumerable<string> CreatePackageFile()
        {
            var packageReferenceFile = new PackageReferenceFile(Path.Combine(_fileSystem.CurrentDirectory, Constants.PackagesFile));
            var repository = new LocalPackageRepository(Path.Combine(_fileSystem.CurrentDirectory, Constants.PackagesFolder));
            var arbitraryPackages = repository.GetPackages();
            var result = new List<string>();

            foreach (var package in arbitraryPackages.GroupBy(i => i.Id))
            {
                var p = package.OrderByDescending(i => i.Version).FirstOrDefault();
                packageReferenceFile.AddEntry(p.Id, p.Version, VersionUtility.ParseFrameworkName("net45"));
                result.Add(string.Format("{0}, Version {1}, .NET 4.5", p.Id, p.Version));
            }

            return result;
        }
		public void CheckProjectPackages (IDotNetProject project)
		{
			packageReferenceFile = CreatePackageReferenceFile (project.GetPackagesConfigFilePath ());
			packageReferences = packageReferenceFile.GetPackageReferences ().ToList ();

			var targetFramework = new ProjectTargetFramework (project);
			compatibilityReport = new ProjectPackagesCompatibilityReport (targetFramework.TargetFrameworkName);

			foreach (PackageReference packageReference in packageReferences) {
				IPackage package = packageRepository.Repository.FindPackage (packageReference.Id);
				if (package != null) {
					if (PackageNeedsReinstall (project, package, packageReference.TargetFramework)) {
						packagesRequiringReinstallation.Add (package);
					}
				}
			}
		}
		public TestablePackageCompatibilityRunner (
			IDotNetProject project,
			IPackageManagementSolution solution,
			IRegisteredPackageRepositories registeredRepositories,
			IPackageManagementProgressMonitorFactory progressMonitorFactory,
			IPackageManagementEvents packageManagementEvents,
			IProgressProvider progressProvider)
			: base (
				project,
				solution,
				registeredRepositories,
				progressMonitorFactory,
				packageManagementEvents,
				progressProvider)
		{
			PackageReferenceFile = new PackageReferenceFile (FileSystem, "packages.config");
		}
Esempio n. 17
0
        public IEnumerable<IPackageReference> FindReferences(string path)
        {
            var packageReferenceFile = new PackageReferenceFile(path);

            var references = packageReferenceFile.GetPackageReferences().ToList();
            if (references.Any())
            {
                foreach (var packageReference in references)
                {
                    yield return new PackageReference(
                            packageReference.Id,
                            packageReference.TargetFramework,
                            packageReference.Version.Version,
                            packageReference.Version.SpecialVersion);
                }

                yield break;
            }

            // No packages.config, check packages folder
            var packagesFolder = Path.Combine(_fileSystem.GetWorkingDirectory(path), Constants.PackagesFolder);
            if (!_fileSystem.DirectoryExists(packagesFolder))
            {
                yield break;
            }

            var repository = new LocalPackageRepository(packagesFolder);

            var arbitraryPackages = repository.GetPackages();
            if (!arbitraryPackages.Any())
            {
                yield break;
            }

            foreach (var arbitraryPackage in arbitraryPackages)
            {
                var newestFramework = GetNewestSupportedFramework(arbitraryPackage)
                    ?? VersionUtility.EmptyFramework;

                yield return new PackageReference(
                        arbitraryPackage.Id,
                        newestFramework,
                        arbitraryPackage.Version.Version,
                        arbitraryPackage.Version.SpecialVersion);
            }
        }
Esempio n. 18
0
        public PackageReferenceRepository(
            string configFilePath,
            ISharedPackageRepository sourceRepository)
        {
            if (String.IsNullOrEmpty(configFilePath))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "configFilePath");
            }

            if (sourceRepository == null)
            {
                throw new ArgumentNullException("sourceRepository");
            }

            _packageReferenceFile = new PackageReferenceFile(configFilePath);
            SourceRepository = sourceRepository;
        }
		public void CheckProjectPackages (IDotNetProject project)
		{
			IPackageManagementProject packageManagementProject = solution.GetProject (registeredRepositories.ActiveRepository, project);

			packageReferenceFile = CreatePackageReferenceFile (project.GetPackagesConfigFilePath ());
			packageReferences = packageReferenceFile.GetPackageReferences ().ToList ();

			compatibilityReport = new ProjectPackagesCompatibilityReport (packageManagementProject.TargetFramework);

			foreach (PackageReference packageReference in packageReferences) {
				IPackage package = packageManagementProject.FindPackage (packageReference.Id);
				if (package != null) {
					if (PackageNeedsReinstall (project, package, packageReference.TargetFramework)) {
						packagesRequiringReinstallation.Add (package);
					}
				}
			}
		}
Esempio n. 20
0
        public void CreatePackageFile()
        {
            var packagesFile = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.PackagesFile);
            var packageReferenceFile = new PackageReferenceFile(packagesFile);

            var packagesFolder = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.PackagesFolder);
            var repository = new LocalPackageRepository(packagesFolder);

            var newestPackages = repository.GetPackages().GroupBy(p => p.Id)
                .Select(g => g.OrderByDescending(p => p.Version).FirstOrDefault());

            if (!newestPackages.Any())
            {
                _logger.Info("No packages found!");
                return;
            }

            _logger.InfoFormat("{0} {1}...", (File.Exists(packagesFile) ? "Updating" : "Creating"), _fileSystem.PackagesFile);

            foreach (var package in newestPackages)
            {
                var newestFramework = GetNewestSupportedFramework(package);

                if (!packageReferenceFile.EntryExists(package.Id, package.Version))
                {
                    packageReferenceFile.AddEntry(package.Id, package.Version, package.DevelopmentDependency, newestFramework);

                    if (newestFramework == null)
                    {
                        _logger.InfoFormat("Added {0} (v{1}) to {2}", package.Id, package.Version, _fileSystem.PackagesFile);
                    }
                    else
                    {
                        _logger.InfoFormat("Added {0} (v{1}, .NET {2}) to {3}", package.Id, package.Version, newestFramework.Version, _fileSystem.PackagesFile);
                    }

                    continue;
                }

                _logger.InfoFormat("Skipped {0} because it already exists.", package.Id);
            }

            _logger.InfoFormat("Successfully {0} {1}.", (File.Exists(packagesFile) ? "updated" : "created"), _fileSystem.PackagesFile);
        }
Esempio n. 21
0
        public PackageReferenceRepository(
            IFileSystem fileSystem, 
            string projectName, 
            ISharedPackageRepository sourceRepository)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException("fileSystem");
            }
            if (sourceRepository == null)
            {
                throw new ArgumentNullException("sourceRepository");
            }

            _packageReferenceFile = new PackageReferenceFile(
                fileSystem, Constants.PackageReferenceFile, projectName);

            SourceRepository = sourceRepository;
        }
Esempio n. 22
0
        //string path)
        //reads all the packages.config files provided as input
        //and returns a map which contains every package mapped to list of project locations in which it is referenced.
        public Dictionary<PackageElement, List<string>> readConfig(List<string> packageFilePaths, string root)
        {
            Dictionary<PackageElement, List<string>> map = new Dictionary<PackageElement, List<string>>();
            string fileName;
            Console.WriteLine("In read config");
            foreach (string path in packageFilePaths)
            {
                //Ignore packages.config files in these folders
                if (path.Contains(@"\.nuget") || path.Contains(@"\packages") || path.Contains(@"\Samples\"))
                    continue;
                fileName = path + "packages.config";
                var file = new PackageReferenceFile(fileName);

                string path1 = path.Replace(root, "");
                Console.WriteLine(path1);
                foreach (PackageReference packageReference in file.GetPackageReferences())
                {
                    PackageElement pe = new PackageElement(packageReference.Id, packageReference.Version);
                    if (!map.ContainsKey(pe))
                    {
                        //Console.WriteLine("add to map: "+packageReference.Id);
                        List<string> ans = new List<string>();
                        ans.Add(path1);
                        map.Add(pe, ans);
                    }
                    else
                    {
                        List<string> ans= map[pe];
                        ans.Add(path1);
                        map[pe] = ans;
                        //Console.WriteLine(" contains key "+ packageReference .Id+" "+ ans.Count);
                    }
                    Console.WriteLine("PackageId={0}, Version={1}", packageReference.Id, packageReference.Version);
                }
            }

            return map;
        }
Esempio n. 23
0
        public IEnumerable<IPackageReference> FindReferences(string path)
        {
            var packageReferenceFile = new PackageReferenceFile(path);
            var references = packageReferenceFile.GetPackageReferences();

            if (!references.Any())
            {
                var packagesFolder = Path.Combine(_fileSystem.GetWorkingDirectory(path), Constants.PackagesFolder);
                if (_fileSystem.DirectoryExists(packagesFolder))
                {
                    var repository = new LocalPackageRepository(packagesFolder);
                    var arbitraryPackages = repository.GetPackages().Where(i => i.GetSupportedFrameworks().Any(x => x.FullName == VersionUtility.ParseFrameworkName("net40").FullName)).ToList();
                    if (arbitraryPackages.Any())
                    {
                        return arbitraryPackages.Select(i => new PackageReference(i.Id, VersionUtility.ParseFrameworkName("net40"), i.Version.Version) { SpecialVersion = i.Version.SpecialVersion });
                    }
                }

                return Enumerable.Empty<IPackageReference>();
            }

            var packages = references.Select(i => new PackageReference(i.Id, i.TargetFramework, i.Version.Version) { SpecialVersion = i.Version.SpecialVersion });
            return packages;
        }
Esempio n. 24
0
        public static ICollection<PackageReference> GetPackageReferences(PackageReferenceFile file, string fileName, bool requireVersion)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            var packageReferences = file.GetPackageReferences(requireVersion).ToList();
            foreach (var package in packageReferences)
            {
                // GetPackageReferences returns all records without validating values. We'll throw if we encounter packages
                // with malformed ids / Versions.
                if (String.IsNullOrEmpty(package.Id))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandInvalidPackageReference, fileName));
                }
                if (requireVersion && (package.Version == null))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, package.Id));
                }
            }

            return packageReferences;
        }
		void AssertPackageMarkedForReinstallationInPackagesConfigFile (string packageId, bool expectedReinstallationSetting)
		{
			var fileSystem = new FakeFileSystem ();
			fileSystem.FileExistsReturnValue = true;
			MemoryStream stream = runner.FileSystem.FilesAdded.First ().Value;
			string file = UTF8Encoding.UTF8.GetString (stream.ToArray ());
			fileSystem.FileToReturnFromOpenFile = file;
			var packageReferenceFile = new PackageReferenceFile (fileSystem, "packages.config");
			PackageReference matchedReference = packageReferenceFile
				.GetPackageReferences ()
				.FirstOrDefault (packageReference => packageReference.Id == packageId);

			Assert.AreEqual (expectedReinstallationSetting, matchedReference.RequireReinstallation);
		}
 public PackageReferenceFile(string fileName)
 {
     this.fileName = fileName;
     this.file = new NuGet.PackageReferenceFile(fileName);
 }
Esempio n. 27
0
        private static void WriteLicenseInformationToOutputFile(List<string> configDirs, string packageDir, string outputFile)
        {
            var packageBuilder = new StringBuilder();
            var licenseTemplate = EmbeddedResourceExtracter.LoadEmbeddedTextFile(
                Assembly.GetExecutingAssembly(),
                @"NTreva.Templates.LicenseInformation.xml");

            // Determine all the packages we need to scan from the packages.config files
            var usedPackages = new List<Tuple<string, string>>();
            foreach (var dir in configDirs)
            {
                var configFile = Path.Combine(dir, "packages.config");

                var file = new PackageReferenceFile(configFile);
                var packageReferences = file.GetPackageReferences().ToList();

                // Note that we ignore dependencies here because packages.config already contains the full closure
                foreach (var package in packageReferences)
                {
                    // GetPackageReferences returns all records without validating values. We'll throw if we encounter packages
                    // with malformed ids.
                    if (string.IsNullOrEmpty(package.Id))
                    {
                        throw new InvalidDataException(Resources.Exceptions_Messages_InvalidPackageId);
                    }

                    if (!usedPackages.Exists(t => string.Equals(t.Item1, package.Id)))
                    {
                        usedPackages.Add(new Tuple<string, string>(package.Id, package.Version.ToString()));
                    }
                }
            }

            usedPackages.Sort();
            foreach (var tuple in usedPackages)
            {
                WriteToConsole(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.Output_ProcessingPackage,
                        tuple.Item1));

                // Go find the package from the packages directory
                var packageFilePath = Path.Combine(
                    Path.Combine(
                        packageDir,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "{0}.{1}",
                            tuple.Item1,
                            tuple.Item2)),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}.{1}.{2}",
                        tuple.Item1,
                        tuple.Item2,
                        "nupkg"));
                if (File.Exists(packageFilePath))
                {
                    var packageFile = new ZipPackage(packageFilePath);

                    var licenseBuilder = new StringBuilder(licenseTemplate);
                    licenseBuilder.Replace(@"${Package.Id}$", packageFile.Id);

                    var version = packageFile.Version ?? new SemanticVersion(new Version());
                    licenseBuilder.Replace(@"${Package.Version}$", version.ToString());

                    var projectUrl = packageFile.ProjectUrl
                            ?? new Uri(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    Resources.GoogleSearchQuery,
                                    tuple.Item1.Replace(' ', '+')));
                    licenseBuilder.Replace(@"${Package.Url}$", projectUrl.ToString());

                    var licenseUrl = packageFile.LicenseUrl
                        ?? new Uri(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                Resources.GoogleSearchQuery,
                                tuple.Item1.Replace(' ', '+')));
                    licenseBuilder.Replace(@"${Package.LicenseUrl}$", licenseUrl.ToString());

                    if (packageBuilder.Length > 0)
                    {
                        packageBuilder.Append(Environment.NewLine);
                    }

                    packageBuilder.Append(licenseBuilder);
                }
            }

            var packagesTemplate = EmbeddedResourceExtracter.LoadEmbeddedTextFile(
                Assembly.GetExecutingAssembly(),
                @"NTreva.Templates.Packages.xml");

            var builder = new StringBuilder(packagesTemplate);
            builder.Replace(@"${Packages}$", packageBuilder.ToString());

            using (var writer = new StreamWriter(new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None), Encoding.UTF8))
            {
                writer.Write(builder.ToString());
            }

            WriteToConsole(
                string.Format(
                    CultureInfo.CurrentCulture,
                    Resources.Output_Completed,
                    outputFile));
        }
Esempio n. 28
0
        public static IEnumerable<PackageReference> GetPackageReferences(this ICakeContext context, DirectoryPath path)
        {
            if (!path.IsRelative)
            {
                throw new CakeException("DirectoryPath must be relative!");
            }

            var packagePath = path.CombineWithFilePath(new FilePath("packages.config"));
            if (!System.IO.File.Exists(packagePath.FullPath))
            {
                throw new CakeException(string.Format("Could not find a packages.config file in '{0}'", path.FullPath));
            }

            var file = new PackageReferenceFile(packagePath.FullPath);
            return file.GetPackageReferences();
        }
Esempio n. 29
0
        public static PackageReference GetPackageReference(this ICakeContext context, DirectoryPath path, string packageId)
        {
            if (!path.IsRelative)
            {
                throw new CakeException("DirectoryPath must be relative!");
            }

            var packagePath = path.CombineWithFilePath(new FilePath("packages.config"));
            if (!System.IO.File.Exists(packagePath.FullPath))
            {
                throw new CakeException(string.Format("Could not find a packages.config file in '{0}'", path.FullPath));
            }

            var file = new PackageReferenceFile(packagePath.FullPath);
            return file.GetPackageReferences().FirstOrDefault(x => x.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 30
0
        public static ICollection <InstalledPackageReference> GetInstalledPackageReferences(PackageReferenceFile configFile, bool requireVersion)
        {
            if (configFile == null)
            {
                throw new ArgumentNullException("configFile");
            }

            var packageReferences = configFile.GetPackageReferences(requireVersion);

            foreach (var package in packageReferences)
            {
                // GetPackageReferences returns all records without validating values. We'll throw if we encounter packages
                // with malformed ids / Versions.
                if (String.IsNullOrEmpty(package.Id))
                {
                    throw new InvalidDataException(
                              String.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("InstallCommandInvalidPackageReference"),
                                            configFile.FullPath));
                }
                if (requireVersion && (package.Version == null))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("InstallCommandPackageReferenceInvalidVersion"), package.Id));
                }
            }

            return(packageReferences.Select(pr => CoreConverters.SafeToInstalledPackageReference(pr)).ToList());
        }
Esempio n. 31
0
 //writes new version of the package to packages.config file
 public void writeToConfig(string fileName, string packageId, SemanticVersion newversion)
 {
     var file = new PackageReferenceFile(fileName);
     file.DeleteEntry(packageId, null);
     file.AddEntry(packageId, newversion);
 }
		protected virtual IEnumerable<PackageReference> GetPackageReferences ()
		{
			if (project.HasPackages ()) {
				var packageReferenceFile = new PackageReferenceFile (project.GetPackagesConfigFilePath ());
				return packageReferenceFile.GetPackageReferences ();
			}
			return new PackageReference [0];
		}
 public void RegisterRepository(PackageReferenceFile packageReferenceFile)
 {
     AddEntry(packageReferenceFile.FullPath);
 }
 public void UnregisterRepository(PackageReferenceFile packageReferenceFile)
 {
     DeleteEntry(packageReferenceFile.FullPath);
 }
        private static List<PackageReferenceFile> GetPackageReferenceFileList()
        {
            var x1 = @"<?xml version='1.0' encoding='utf-8'?>
                    <packages>
                      <package id='Package1' version='1.0' allowedVersions='[1.0, 2.0)' />
                      <package id='Package2' version='2.0' />
                    </packages>";

            var x2 = @"<?xml version='1.0' encoding='utf-8'?>
                    <packages>
                      <package id='Package1' version='2.0' allowedVersions='[1.0, 3.0)' />
                      <package id='Package2' version='2.0' />
                    </packages>";

            var mfs = new Mock<MockFileSystem>();
            mfs.Setup(m => m.OpenFile("x1")).Returns(x1.AsStream());
            mfs.Setup(m => m.OpenFile("x2")).Returns(x2.AsStream());
            mfs.Setup(m => m.FileExists(It.IsAny<string>())).Returns(true);

            var mpr1 = new PackageReferenceFile(mfs.Object, "x1");
            var mpr2 = new PackageReferenceFile(mfs.Object, "x2");

            var packageFiles = new List<PackageReferenceFile>();
            packageFiles.Add(mpr1);
            packageFiles.Add(mpr2);
            return packageFiles;
        }
        /*<summary>
        *   Using Nuget.Core API, we gather all nuget`s packages that specific project depend on them.
        * </summary>
        * <returns></returns>
        */
        private static void addDependencies(string projectName, Module module, string localSource, string[] packageConfigPath, string Configuration)
        {
            if (packageConfigPath.Length != 0)
            {
                var sharedPackages = new LocalPackageRepository(localSource);
                var packageReferenceFile = new PackageReferenceFile(packageConfigPath[0]);
                IEnumerable<PackageReference> projectPackages = packageReferenceFile.GetPackageReferences();

                foreach (PackageReference package in projectPackages)
                {
                    var pack = sharedPackages.FindPackage(package.Id, package.Version);

                    using (Stream packageStream = ((NuGet.OptimizedZipPackage)(pack)).GetStream())
                    {
                        byte[] buf = new byte[packageStream.Length];
                        int byteread = packageStream.Read(buf, 0, buf.Length);

                        module.Dependencies.Add(new Dependency
                        {
                            type = "nupkg",
                            md5 = MD5CheckSum.GenerateMD5(buf),
                            sha1 = Sha1Reference.GenerateSHA1(buf),
                            scopes = new List<string> { Configuration },
                            id = pack.Id + ":" + pack.Version
                        });
                    }
                }
            }
        }
Esempio n. 37
0
        static IEnumerable<PackageReference> GetDependencies() {

            if (string.IsNullOrEmpty(packages_config_path)) {
                var currentDir = Directory.GetCurrentDirectory();
                string[] files = Directory.GetFiles(currentDir, "packages.config");
                if (files.Length == 1) {
                    packages_config_path = files[0];
                    log.DebugFormat("packages.config found: {0}", packages_config_path);
                }
            }

            if (packages_config_path == null) return null;

            var packageReferenceFile = new PackageReferenceFile(packages_config_path);
            return packageReferenceFile.GetPackageReferences();
        }
Esempio n. 38
0
 public void RegisterRepository(PackageReferenceFile packageReferenceFile)
 {
     AddEntry(packageReferenceFile.FullPath);
 }
 public void UnregisterRepository(PackageReferenceFile packageReferenceFile)
 {
     throw new NotImplementedException();
 }
Esempio n. 40
0
 public void UnregisterRepository(PackageReferenceFile packageReferenceFile)
 {
     DeleteEntry(packageReferenceFile.FullPath);
 }
Esempio n. 41
0
 public PackageReferenceFile(string fileName)
 {
     this.fileName = fileName;
     this.file     = new NuGet.PackageReferenceFile(fileName);
 }