示例#1
0
 private void AddRemoteProvidersFromSources(List <IWalkProvider> remoteProviders, List <PackageSource> effectiveSources)
 {
     foreach (var source in effectiveSources)
     {
         if (new Uri(source.Source).IsFile)
         {
             remoteProviders.Add(
                 new RemoteWalkProvider(
                     PackageFolderFactory.CreatePackageFolderFromPath(
                         source.Source,
                         Reports.Quiet)));
         }
         else
         {
             remoteProviders.Add(
                 new RemoteWalkProvider(
                     new PackageFeed(
                         source.Source,
                         source.UserName,
                         source.Password,
                         NoCache,
                         Reports,
                         ignoreFailure: IgnoreFailedSources)));
         }
     }
 }
示例#2
0
        public static IPackageFeed CreatePackageFeed(PackageSource source, bool noCache, bool ignoreFailedSources,
                                                     Reports reports)
        {
            if (new Uri(source.Source).IsFile)
            {
                return(PackageFolderFactory.CreatePackageFolderFromPath(source.Source, ignoreFailedSources, reports));
            }
            else
            {
                var httpSource = new HttpSource(
                    source.Source,
                    source.UserName,
                    source.Password,
                    reports);

                Uri packageBaseAddress;
                if (NuGetv3Feed.DetectNuGetV3(httpSource, noCache, out packageBaseAddress))
                {
                    if (packageBaseAddress == null)
                    {
                        reports.Information.WriteLine(
                            $"Ignoring NuGet v3 feed {source.Source.Yellow().Bold()}, which doesn't provide PackageBaseAddress resource.");
                        return(null);
                    }

                    httpSource = new HttpSource(
                        packageBaseAddress.AbsoluteUri,
                        source.UserName,
                        source.Password,
                        reports);

                    return(new NuGetv3Feed(
                               httpSource,
                               noCache,
                               reports,
                               ignoreFailedSources));
                }

                return(new NuGetv2Feed(
                           httpSource,
                           noCache,
                           reports,
                           ignoreFailedSources));
            }
        }
示例#3
0
 public static IPackageFeed CreatePackageFeed(PackageSource source, bool noCache, bool ignoreFailedSources,
                                              Reports reports)
 {
     if (new Uri(source.Source).IsFile)
     {
         return(PackageFolderFactory.CreatePackageFolderFromPath(source.Source, ignoreFailedSources, reports));
     }
     else
     {
         return(new NuGetv2Feed(
                    source.Source,
                    source.UserName,
                    source.Password,
                    noCache,
                    reports,
                    ignoreFailedSources));
     }
 }
示例#4
0
        public static IPackageFeed CreatePackageFeed(PackageSource source, bool noCache, bool ignoreFailedSources,
                                                     Reports reports)
        {
            if (new Uri(source.Source).IsFile)
            {
                return(PackageFolderFactory.CreatePackageFolderFromPath(source.Source, ignoreFailedSources, reports));
            }
            else
            {
                // TODO: temporarily ignore NuGet v3 feeds
                if (source.Source.EndsWith(".json"))
                {
                    return(null);
                }

                return(new NuGetv2Feed(
                           source.Source,
                           source.UserName,
                           source.Password,
                           noCache,
                           reports,
                           ignoreFailedSources));
            }
        }
示例#5
0
        public async Task <bool> ExecuteCommand()
        {
            if (string.IsNullOrEmpty(_addCommand.Name))
            {
                Reports.Error.WriteLine("Name of dependency to install is required.".Red());
                return(false);
            }

            SemanticVersion version = null;

            if (!string.IsNullOrEmpty(_addCommand.Version))
            {
                version = SemanticVersion.Parse(_addCommand.Version);
            }

            // Create source provider from solution settings
            _addCommand.ProjectDir = _addCommand.ProjectDir ?? Directory.GetCurrentDirectory();
            var rootDir    = ProjectResolver.ResolveRootDirectory(_addCommand.ProjectDir);
            var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory());
            var settings   = SettingsUtils.ReadSettings(solutionDir: rootDir,
                                                        nugetConfigFile: null,
                                                        fileSystem: fileSystem,
                                                        machineWideSettings: new CommandLineMachineWideSettings());
            var sourceProvider = PackageSourceBuilder.CreateSourceProvider(settings);

            var effectiveSources = PackageSourceUtils.GetEffectivePackageSources(sourceProvider,
                                                                                 _restoreCommand.Sources, _restoreCommand.FallbackSources);

            var packageFeeds = new List <IPackageFeed>();

            foreach (var source in effectiveSources)
            {
                if (new Uri(source.Source).IsFile)
                {
                    packageFeeds.Add(PackageFolderFactory.CreatePackageFolderFromPath(source.Source, Reports.Quiet));
                }
                else
                {
                    packageFeeds.Add(new PackageFeed(
                                         source.Source, source.UserName, source.Password, _restoreCommand.NoCache, Reports,
                                         _restoreCommand.IgnoreFailedSources));
                }
            }

            PackageInfo result = null;

            if (version == null)
            {
                result = await FindLatestVersion(packageFeeds, _addCommand.Name);
            }
            else
            {
                result = await FindBestMatch(packageFeeds, _addCommand.Name, version);
            }

            if (result == null)
            {
                Reports.Error.WriteLine("Unable to locate {0} >= {1}",
                                        _addCommand.Name.Red().Bold(), _addCommand.Version);
                return(false);
            }

            if (string.IsNullOrEmpty(_addCommand.Version))
            {
                _addCommand.Version = result.Version.ToString();
            }

            return(_addCommand.ExecuteCommand() && (await _restoreCommand.ExecuteCommand()));
        }