Exemplo n.º 1
0
        void UpdateAllPackages(string solutionDir)
        {
            Log(Level.Debug, "Scanning for projects");

            // Search recursively for all packages.config files
            var packagesConfigFiles = Directory.GetFiles(solutionDir, Constants.PackageReferenceFile, SearchOption.AllDirectories);
            var projects            = packagesConfigFiles.Select(GetProject)
                                      .Where(p => p.Project != null)
                                      .ToList();

            if (projects.Count == 0)
            {
                throw new BuildException("No project found", Location);
            }

            string             repositoryPath   = GetRepositoryPathFromSolution(solutionDir);
            IPackageRepository sourceRepository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            foreach (var project in projects)
            {
                try
                {
                    UpdatePackages(project.PackagesConfigPath, project.Project, repositoryPath, sourceRepository);
                }
                catch (Exception e)
                {
                    Log(Level.Error, e.Message);
                }
            }
        }
Exemplo n.º 2
0
        private void GetPackageLocally(string packageId, string version, string workDirectory)
        {
            //Add the default source if there are none present
            var workingFileSystem = new PhysicalFileSystem(workDirectory);

            foreach (string source in Sources)
            {
                Uri uri;
                if (Uri.TryCreate(source, UriKind.Absolute, out uri))
                {
                    AggregateRepository repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(PackageRepositoryFactory.Default, CreateSourceProvider(new[] { source }), new[] { source });

                    IPackage package;
                    if (repository.TryFindPackage(packageId, new SemanticVersion(version), out package))
                    {
                        Console.WriteLine("Attempting to download package {0}.{1} via {2}", packageId, version, uri.ToString());

                        try {
                            string filepath = Path.Combine(workDirectory, package.Id + "-" + package.Version + ".nupkg");
                            workingFileSystem.AddFile(filepath, package.GetStream());
                            break;
                        }
                        catch (Exception e) {
                            Console.WriteError(e);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private IPackageRepository GetRepository(IPackageSourceProvider sourceProvider, IList <string> source)
        {
            var repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, sourceProvider, source);

            repository.Logger = Console;
            return(repository);
        }
Exemplo n.º 4
0
        private IPackageRepository GetRepository()
        {
            var repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            repository.Logger = Console;
            return(repository);
        }
Exemplo n.º 5
0
        private ProjectNugetifier CreateProjectNugetifier(IVsProject projectAdapter)
        {
            var projectFileSystem = new PhysicalFileSystem(projectAdapter.ProjectDirectory.ToString());
            var repository        = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            repository.Logger = Console;
            var hintPathGenerator = new HintPathGenerator(!ExcludeVersion);

            return(new ProjectNugetifier(projectAdapter, repository, projectFileSystem, Console, hintPathGenerator));
        }
Exemplo n.º 6
0
        void InstallAllPackages(string solutionDir)
        {
            Console.WriteLine(LocalizedResourceManager.GetString("ScanningForProjects"));

            // Search recursively for all packages.xxx.config files
            string[] packagesConfigFiles = Directory.GetFiles(
                solutionDir, "*.config", SearchOption.AllDirectories);

            var projects = packagesConfigFiles.Where(s => Path.GetFileName(s).StartsWith("packages.", StringComparison.OrdinalIgnoreCase))
                           .Select(GetProject)
                           .Where(p => p != null)
                           .Distinct()
                           .ToList();

            if (projects.Count == 0)
            {
                Console.WriteLine(LocalizedResourceManager.GetString("NoProjectsFound"));
                return;
            }

            if (projects.Count == 1)
            {
                Console.WriteLine(LocalizedResourceManager.GetString("FoundProject"), projects.Single().ProjectName);
            }
            else
            {
                Console.WriteLine(LocalizedResourceManager.GetString("FoundProjects"), projects.Count, String.Join(", ", projects.Select(p => p.ProjectName)));
            }

            string             repositoryPath   = GetRepositoryPathFromSolution(solutionDir);
            IPackageRepository sourceRepository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            foreach (var project in projects)
            {
                try
                {
                    UpdatePackages(project, repositoryPath, sourceRepository);
                    if (Verbose)
                    {
                        Console.WriteLine();
                    }
                }
                catch (Exception e)
                {
                    if (Console.Verbosity == NuGet.Verbosity.Detailed)
                    {
                        Console.WriteWarning(e.ToString());
                    }
                    else
                    {
                        Console.WriteWarning(e.Message);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public void TestFixtureSetUp()
 {
     _mockFileSystem = new MockFileSystem();
     _packageManager = new PackageManager(
         AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(Utilities.GetFactory(),
                                                                        Utilities.GetSourceProvider(),
                                                                        new List <string>()
     {
         "Dev"
     }),
         new DefaultPackagePathResolver(_mockFileSystem), _mockFileSystem);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the repository.
        /// </summary>
        /// <returns></returns>
        private IPackageRepository GetRepository()
        {
            var  repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            bool ignoreFailingRepositories = repository.IgnoreFailingRepositories;

            if (!NoCache)
            {
                repository = new AggregateRepository(new[] { CacheRepository, repository })
                {
                    IgnoreFailingRepositories = ignoreFailingRepositories, Logger = Console
                };
            }
            repository.Logger = Console;
            return(repository);
        }
        protected IPackageRepository CreateRepository()
        {
            AggregateRepository repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            repository.Logger = Console;

            if (NoCache)
            {
                return(repository);
            }
            else
            {
                return(new AggregateRepository(new[] { CacheRepository, repository }));
            }
        }
Exemplo n.º 10
0
        private void UpdateAllPackages(string solutionDir)
        {
            Console.WriteLine(NuGetResources.ScanningForProjects);

            // Search recursively for all packages.config files
            var packagesConfigFiles = Directory.GetFiles(solutionDir, Constants.PackageReferenceFile, SearchOption.AllDirectories);
            var projects            = packagesConfigFiles.Select(GetProject)
                                      .Where(p => p.Project != null)
                                      .ToList();


            if (projects.Count == 0)
            {
                Console.WriteLine(NuGetResources.NoProjectsFound);
                return;
            }

            if (projects.Count == 1)
            {
                Console.WriteLine(NuGetResources.FoundProject, projects.Single().Project.ProjectName);
            }
            else
            {
                Console.WriteLine(NuGetResources.FoundProjects, projects.Count, String.Join(", ", projects.Select(p => p.Project.ProjectName)));
            }

            string             repositoryPath   = GetRepositoryPathFromSolution(solutionDir);
            IPackageRepository sourceRepository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            foreach (var project in projects)
            {
                try
                {
                    UpdatePackages(project.PackagesConfigPath, project.Project, repositoryPath, sourceRepository);
                    if (Verbose)
                    {
                        Console.WriteLine();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteWarning(e.Message);
                }
            }
        }
Exemplo n.º 11
0
        private void UpdatePackages(IMSBuildProjectSystem projectSystem, string repositoryPath = null, IPackageRepository sourceRepository = null)
        {
            // Resolve the repository path
            repositoryPath = repositoryPath ?? GetRepositoryPath(projectSystem.Root);

            var sharedRepositoryFileSystem = new PhysicalFileSystem(repositoryPath);
            var pathResolver = new DefaultPackagePathResolver(sharedRepositoryFileSystem);

            // Create the local and source repositories
            var sharedPackageRepository = new SharedPackageRepository(pathResolver, sharedRepositoryFileSystem, sharedRepositoryFileSystem);
            var localRepository         = new PackageReferenceRepository(projectSystem, projectSystem.ProjectName, sharedPackageRepository);

            sourceRepository = sourceRepository ?? AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            Console.WriteLine(LocalizedResourceManager.GetString("UpdatingProject"), projectSystem.ProjectName);
            UpdatePackages(localRepository, sharedRepositoryFileSystem, sharedPackageRepository, sourceRepository, localRepository, pathResolver, projectSystem);
            projectSystem.Save();
        }
Exemplo n.º 12
0
        private void UpdatePackages(string packagesConfigPath, IMSBuildProjectSystem project = null, string repositoryPath = null, IPackageRepository sourceRepository = null)
        {
            // Get the msbuild project
            project = project ?? GetMSBuildProject(packagesConfigPath);

            // Resolve the repository path
            repositoryPath = repositoryPath ?? GetReposioryPath(project.Root);

            var pathResolver = new DefaultPackagePathResolver(repositoryPath);

            // Create the local and source repositories
            var localRepository = new PackageReferenceRepository(project, new SharedPackageRepository(repositoryPath));

            sourceRepository = sourceRepository ?? AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            IPackageConstraintProvider constraintProvider = localRepository;

            Console.WriteLine(NuGetResources.UpdatingProject, project.ProjectName);
            UpdatePackages(localRepository, sourceRepository, constraintProvider, pathResolver, project);
            project.Save();
        }
Exemplo n.º 13
0
        private IEnumerable <PackageDependency> GetReferences(string packagesConfigPath, IMSBuildProjectSystem project = null, string repositoryPath = null, IPackageRepository sourceRepository = null)
        {
            // Get the msbuild project
            project = project ?? NugetUpdateTask.GetMSBuildProject(packagesConfigPath);

            // Resolve the repository path
            repositoryPath = repositoryPath ?? GetRepositoryPath(project.Root);

            var sharedRepositoryFileSystem = new PhysicalFileSystem(repositoryPath);
            var pathResolver = new DefaultPackagePathResolver(sharedRepositoryFileSystem);

            // Create the local and source repositories
            var sharedPackageRepository = new SharedPackageRepository(pathResolver, sharedRepositoryFileSystem, sharedRepositoryFileSystem);
            var localRepository         = new PackageReferenceRepository(project, sharedPackageRepository);

            sourceRepository = sourceRepository ?? AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            IPackageConstraintProvider constraintProvider = localRepository;

            return(GetReferences(localRepository, sharedRepositoryFileSystem, sharedPackageRepository, sourceRepository, constraintProvider, pathResolver, project));
        }
Exemplo n.º 14
0
        protected virtual IPackageRepository GetRepository()
        {
            var aggregateRepository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, (IEnumerable <string>)Source);
            var failingRepositories = aggregateRepository.IgnoreFailingRepositories;

            if (!NoCache)
            {
                aggregateRepository = new AggregateRepository((IEnumerable <IPackageRepository>) new IPackageRepository[2] {
                    CacheRepository,
                    (IPackageRepository)aggregateRepository
                })
                {
                    IgnoreFailingRepositories = failingRepositories
                }
            }
            ;
            aggregateRepository.Logger = (ILogger)Console;
            return((IPackageRepository)aggregateRepository);
        }
    }
Exemplo n.º 15
0
        private void UpdatePackages(string packagesConfigPath, IMSBuildProjectSystem project = null, string repositoryPath = null, IPackageRepository sourceRepository = null)
        {
            // Get the msbuild project
            project = project ?? GetMSBuildProject(packagesConfigPath);

            // Resolve the repository path
            repositoryPath = repositoryPath ?? GetRepositoryPath(project.Root);

            var sharedRepositoryFileSystem = new PhysicalFileSystem(repositoryPath);
            var pathResolver = new DefaultPackagePathResolver(sharedRepositoryFileSystem);

            // Create the local and source repositories
            var sharedPackageRepository = new SharedPackageRepository(pathResolver, sharedRepositoryFileSystem, sharedRepositoryFileSystem);
            var localRepository         = new PackageReferenceRepository(project, sharedPackageRepository);

            sourceRepository = sourceRepository ?? AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            IPackageConstraintProvider constraintProvider = localRepository;

            Log(Level.Info, "Updating project {0}", project.ProjectName);
            UpdatePackages(localRepository, sharedRepositoryFileSystem, sharedPackageRepository, sourceRepository, constraintProvider, pathResolver, project);
            project.Save();
        }
Exemplo n.º 16
0
        protected override void ExecuteTask()
        {
            if (ProjectFile == null && ProjectDir == null)
            {
                throw new ValidationException("Either project or project-dir must be set on <nuget-get-dependencies />.");
            }

            string dir = SolutionDir.FullName;

            _fileSystem = new PhysicalFileSystem(dir);

            string projectDir = ProjectFile == null ? ProjectDir.FullName : ProjectFile.Directory.FullName;

            RepositoryFactory = new PackageRepositoryFactory();
            SourceProvider    = new PackageSourceProvider(new Settings(_fileSystem));

            var packagesConfigFiles = Directory.GetFiles(projectDir, Constants.PackageReferenceFile, SearchOption.AllDirectories);
            var project             = packagesConfigFiles.Select(GetProject)
                                      .Where(p => p.Project != null)
                                      .SingleOrDefault();

            if (project == null)
            {
                throw new BuildException("No project found", Location);
            }

            string             repositoryPath   = GetRepositoryPathFromSolution(dir);
            IPackageRepository sourceRepository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);

            var references = GetReferences(project.PackagesConfigPath, project.Project, repositoryPath, sourceRepository);
            var deps       = new NuGetDependencies
            {
                Dependencies = references.Select(GetDependency).ToArray()
            };

            Project.DataTypeReferences.Add(ReferenceId, deps);
            Log(Level.Info, "Found {0} dependencies", deps.Dependencies.Length);
        }
Exemplo n.º 17
0
        public override void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Directory))
            {
                Directory = Environment.CurrentDirectory;
            }

            if (_repository == null)
            {
                _repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            }

            var packageFiles = _fileSystem.GetFiles(Directory, "packages.config", true).ToList();

            Console.WriteLine("Processing : {0} files.", packageFiles.Count);
            Parallel.ForEach(packageFiles, packageFile =>
            {
                Console.WriteLine("\t{0}", packageFile);
                var newReferences      = new List <PackageReference>();
                var packageFileDetails = new PackageReferenceFile(_fileSystem, packageFile);
                foreach (var packageReference in packageFileDetails.GetPackageReferences())
                {
                    Console.WriteLine("\t\t{0}", packageReference.ToString());
                    var exists = _repository.FindPackage(packageReference.Id, packageReference.Version);
                    if (exists != null)
                    {
                        Console.WriteLine("\t\t\tExists, not changing.");
                        newReferences.Add(packageReference);
                    }
                    else
                    {
                        var package = _repository.FindPackagesById(packageReference.Id).FirstOrDefault();
                        if (package == null)
                        {
                            Console.WriteLine("\t\t\tNot found, no change.");
                            newReferences.Add(packageReference);
                        }
                        else
                        {
                            var newReference = new PackageReference(package.Id, package.Version, new VersionSpec(), new FrameworkName(".NET Framework, Version=4.0"), false);
                            Console.WriteLine("\t\t\tUpdated to {0}", newReference.ToString());
                            newReferences.Add(newReference);
                        }
                    }
                }

                //TODO Clear the file (must be an easier way).
                Console.WriteLine("Clearing existing file...");
                foreach (var packageReference in packageFileDetails.GetPackageReferences())
                {
                    packageFileDetails.DeleteEntry(packageReference.Id, packageReference.Version);
                }

                //Add the new references.
                Console.WriteLine("Adding new references...");
                foreach (var packageReference in newReferences)
                {
                    packageFileDetails.AddEntry(packageReference.Id, packageReference.Version);
                }
            });
        }