Exemple #1
0
        protected void InitializePackageSources()
        {
            var settings = Settings.LoadDefaultSettings(new PhysicalFileSystem("C:\\"), null, null);
            var packageSourceProvider = new PackageSourceProvider(settings);
            var packageSources        = packageSourceProvider.GetEnabledPackageSources().ToList();

            HttpClient.DefaultCredentialProvider = new SettingsCredentialProvider(new DotPeekCredentialProvider(), packageSourceProvider);

            if (!packageSources.Any())
            {
                packageSources.Add(PluginConstants.NuGetPackageSource);
            }

            foreach (var packageSource in packageSources)
            {
                PackageSources.Add(new Uri(packageSource.Source));
            }

            PackageSource = PackageSources.First();
        }
        /// <summary>
        /// Creates and returns an aggregate repository using the specified settings
        /// </summary>
        public static IPackageRepository CreateRepository(ISettings settings, Common.ILogger logger)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            // Load the user and machine-wide settings
            logger.LogDebug(UIResources.NG_FetchingConfigFiles);

            // Get a package source provider that can use the settings
            PackageSourceProvider packageSourceProvider = new PackageSourceProvider(settings);

            logger.LogDebug(UIResources.NG_ListingEnablePackageSources);
            IEnumerable <PackageSource> enabledSources = packageSourceProvider.GetEnabledPackageSources();

            if (!enabledSources.Any())
            {
                logger.LogWarning(UIResources.NG_NoEnabledPackageSources);
            }
            else
            {
                foreach (PackageSource enabledSource in enabledSources)
                {
                    logger.LogDebug(UIResources.NG_ListEnabledPackageSource, enabledSource.Source, enabledSource.IsMachineWide);
                }
            }

            // Create an aggregate repository that uses all of the configured sources
            AggregateRepository aggRepo = packageSourceProvider.CreateAggregateRepository(PackageRepositoryFactory.Default,
                                                                                          true /* ignore failing repos. Errors will be logged as warnings. */);

            aggRepo.Logger = new NuGetLoggerAdapter(logger);

            return(aggRepo);
        }
        protected IEnumerable <FileSystemPath> GetPackagesToOpen(PackageReferenceFile packagesConfig)
        {
            var settings = Settings.LoadDefaultSettings(new PhysicalFileSystem("C:\\"), null, null);
            var packageSourceProvider = new PackageSourceProvider(settings);
            var packageSources        = packageSourceProvider.GetEnabledPackageSources().ToList();

            if (!packageSources.Any())
            {
                packageSources.Add(PluginConstants.NuGetPackageSource);
            }

            var repository = new AggregateRepository(packageSources
                                                     .Select(s => PackageRepositoryFactory.Default.CreateRepository(s.Source)));

            List <FileSystemPath> returnValue = new List <FileSystemPath>();

            foreach (var package in packagesConfig.GetPackageReferences())
            {
                returnValue.AddRange(GetPackagesToOpen(repository, package.Id, package.Version.ToString(), false));
            }

            return(returnValue);
        }