NuGet.PackageSourceProvider.LoadPackageSources C# (CSharp) Method

LoadPackageSources() public method

Returns PackageSources if specified in the config file. Else returns the default sources specified in the constructor. If no default values were specified, returns an empty sequence.
public LoadPackageSources ( ) : IEnumerable
return IEnumerable
        public IEnumerable<PackageSource> LoadPackageSources()
        {
            IList<KeyValuePair<string, string>> settingsValue = _settingsManager.GetValues(PackageSourcesSectionName);
            if (!settingsValue.IsEmpty())
            {
                // put disabled package source names into the hash set

                IEnumerable<KeyValuePair<string, string>> disabledSourcesValues = _settingsManager.GetValues(DisabledPackageSourcesSectionName) ??
                                                                                  Enumerable.Empty<KeyValuePair<string, string>>();
                var disabledSources = new HashSet<string>(disabledSourcesValues.Select(s => s.Key), StringComparer.CurrentCultureIgnoreCase);
                var loadedPackageSources = settingsValue.
                                           Select(p =>
                                           {
                                               string name = p.Key;
                                               string src = p.Value;
                                               NetworkCredential creds = ReadCredential(name);

                                               // We always set the isOfficial bit to false here, as Core doesn't have the concept of an official package source.
                                               return new PackageSource(src, name, isEnabled: !disabledSources.Contains(name), isOfficial: false)
                                               {
                                                   UserName = creds != null ? creds.UserName : null,
                                                   Password = creds != null ? creds.Password : null
                                               };

                                           }).ToList();

                if (_migratePackageSources != null)
                {
                    MigrateSources(loadedPackageSources);
                }

                return loadedPackageSources;
            }
            return _defaultPackageSources;
        }

Usage Example

Ejemplo n.º 1
0
        public IEnumerable<string> GetRepositorySources(string path)
        {
            var configFileSystem = new PhysicalFileSystem(path);

            ISettings settings;
            if (_fileSystem.FileExists(Path.Combine(_fileSystem.CurrentDirectory, Constants.NugetFile)))
            {
                settings = new Settings(configFileSystem, Constants.NugetFile);
            }
            else
            {
                settings = Settings.LoadDefaultSettings(configFileSystem, null, new NugetMachineWideSettings());
            }

            if (settings == null)
            {
                return new[] { Constants.DefaultRepositoryUrl };
            }

            var sourceProvider = new PackageSourceProvider(settings);
            var sources = sourceProvider.LoadPackageSources().Where(i => i.IsEnabled == true);

            if (sources == null || !sources.Any())
            {
                return new[] { Constants.DefaultRepositoryUrl };
            }

            return sources.Select(i => i.Source);
        }
All Usage Examples Of NuGet.PackageSourceProvider::LoadPackageSources