Ejemplo n.º 1
0
        public NuGetMachineWidePackageSources([NotNull] ISnapFilesystem filesystem, [NotNull] string workingDirectory)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            var nugetMachineWideSettings = new NuGetMachineWideSettings(filesystem, workingDirectory);
            var packageSources           = new List <PackageSource>();

            var nugetConfigReader = new NuGetConfigFileReader();

            foreach (var packageSource in nugetConfigReader.ReadNugetSources(workingDirectory).Where(x => x.IsEnabled))
            {
                if (!packageSources.Contains(packageSource))
                {
                    packageSources.Add(packageSource);
                }
            }

            Items    = packageSources;
            Settings = nugetMachineWideSettings.Settings;
        }
Ejemplo n.º 2
0
        public NuGetMachineWidePackageSources([NotNull] ISnapFilesystem filesystem, [NotNull] string workingDirectory)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            var nugetMachineWideSettings = new NuGetMachineWideSettings(filesystem, workingDirectory);

            var nugetConfigAbsolutePath = filesystem.DirectoryGetAllFiles(workingDirectory)
                                          .FirstOrDefault(x => x.EndsWith("nuget.config", StringComparison.OrdinalIgnoreCase));

            var packageSources = new List <PackageSource>();

            if (nugetConfigAbsolutePath != null)
            {
                var nugetConfigReader = new NuGetConfigFileReader();
                foreach (var packageSource in nugetConfigReader.ReadNugetSources(workingDirectory).Where(x => x.IsEnabled))
                {
                    if (!packageSources.Contains(packageSource))
                    {
                        packageSources.Add(packageSource);
                    }
                }
            }
            else
            {
                var packageSourceProvider = new PackageSourceProvider(nugetMachineWideSettings.Settings);
                packageSources = packageSourceProvider.LoadPackageSources().Where(x => x.IsEnabled).ToList();
            }

            Items    = packageSources;
            Settings = nugetMachineWideSettings.Settings;
        }