public NuGetProject(List <string> packagesList, string packagesPath, ProjectFile projectFile, ILog log)
            {
                this.log          = log;
                this.packagesList = packagesList;
                this.projectFile  = projectFile;
                installedPackages = new HashSet <PackageIdentity>();
                var sourceProvider           = new PackageSourceProvider(Settings.LoadDefaultSettings(null));
                var sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(sourceProvider);

                repositories = sourceProvider.LoadPackageSources().Select(sourceRepositoryProvider.CreateRepository)
                               .ToList();
                logger = new Console();

                var projectFilePath = projectFile.FilePath;

                var msbuildDirectory =
                    Path.GetDirectoryName(ModuleBuilderHelper.FindMsBuild(null, "Cement NuGet Package Installer"));

                projectContext = new ConsoleProjectContext(logger);
                projectSystem  = new MSBuildProjectSystem(
                    msbuildDirectory,
                    projectFilePath,
                    projectContext);
                var projectFolder = Path.GetDirectoryName(projectFilePath);

                project = new MSBuildNuGetProject(projectSystem, packagesPath, projectFolder);
            }
Example #2
0
        private IEnumerable <SourceRepository> GetInternalRepository(string pathToSolution)
        {
            var setting = Settings.LoadDefaultSettings(pathToSolution);
            var sourceRepositoryProvider = new SourceRepositoryProvider(
                new PackageSourceProvider(setting),
                Repository.Provider.GetCoreV3());

            var repositories = sourceRepositoryProvider
                               .GetRepositories()
                               .Where(r => r.PackageSource.Name.ToLower() != "nuget.org");

            return(repositories);
        }
Example #3
0
        private IEnumerable <SourceRepository> GetInternalRepository(string pathToSolution)
        {
            var setting = Settings.LoadDefaultSettings(pathToSolution);
            var sourceRepositoryProvider = new SourceRepositoryProvider(
                new PackageSourceProvider(setting),
                Repository.Provider.GetCoreV3());

            var repositories = sourceRepositoryProvider
                               .GetRepositories()
                               .Where(r => !string.Equals(r.PackageSource.Name, "nuget.org", StringComparison.OrdinalIgnoreCase));

            return(repositories);
        }
            private DownloadResourceResult LoadPackage(PackageIdentity package,
                                                       PackageDownloadContext packageDownloadContext)
            {
                var downloadResourceResult = PackageDownloader.GetDownloadResourceResultAsync(
                    repositories,
                    package,
                    packageDownloadContext,
                    SettingsUtility.GetGlobalPackagesFolder(Settings.LoadDefaultSettings(null)),
                    logger,
                    CancellationToken.None
                    ).Result;

                return(downloadResourceResult);
            }
Example #5
0
        public NuGetViewModel()
        {
            _settings = Settings.LoadDefaultSettings(
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                configFileName: null,
                machineWideSettings: new CommandLineMachineWideSettings());

            _sourceProvider = new PackageSourceProvider(_settings);

            GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(_settings);

            _packageSources = GetPackageSources();

            _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(_sourceProvider);

            _initializationTask = new Lazy <Task>(Initialize);
        }
Example #6
0
        public virtual IEnumerable <SourceRepository> GetInternalRepositories(string pathToSolution)
        {
            string solutionDirectory        = Path.GetDirectoryName(pathToSolution);
            var    settings                 = Settings.LoadDefaultSettings(solutionDirectory);
            var    sourceRepositoryProvider = new SourceRepositoryProvider(
                new PackageSourceProvider(settings),
                Repository.Provider.GetCoreV3());

            var repositories = sourceRepositoryProvider
                               .GetRepositories()
                               .Where(r =>
                                      !string.Equals(r.PackageSource.Name, "nuget.org", StringComparison.OrdinalIgnoreCase) &&
                                      r.PackageSource.IsEnabled &&
                                      !string.Equals(r.PackageSource.Name, "microsoft visual studio offline packages", StringComparison.OrdinalIgnoreCase))
                               .ToList();

            return(repositories);
        }
Example #7
0
        public void GetDefaultPackageSourcesFromSourceProvider()
        {
            // Arrange
            using (var mockBaseDirectory = TestFileSystemUtility.CreateRandomTestFolder())
            {
                var configurationDefaultsContent = @"
<configuration>
    <packageSources>
        <add key='Contoso Package Source' value='http://contoso.com/packages/' />
    </packageSources>
      <config>
        <add key='DefaultPushSource' value='http://contoso.com/packages/' />
    </config>
</configuration>";
                var config = @"
<configuration>
    <packageSources>
        <add key='v2' value='http://www.nuget.org/api/v2/' />
    </packageSources>
</configuration>";

                File.WriteAllText(Path.Combine(mockBaseDirectory, "NuGet.Config"), config);
                var settings = Settings.LoadDefaultSettings(mockBaseDirectory,
                                                            configFileName: null,
                                                            machineWideSettings: null,
                                                            loadAppDataSettings: false,
                                                            useTestingGlobalPath: false);
                ConfigurationDefaults ConfigurationDefaults = GetConfigurationDefaults(configurationDefaultsContent, mockBaseDirectory);

                var packageSourceProvider = new PackageSourceProvider(settings, null, ConfigurationDefaults.DefaultPackageSources);

                // Act
                List <PackageSource> packageSources = packageSourceProvider.LoadPackageSources().ToList();

                // Assert
                Assert.Equal("http://contoso.com/packages/", ConfigurationDefaults.DefaultPushSource);
                Assert.Equal(2, packageSources.Count());
                Assert.Equal("v2", packageSources[0].Name);
                Assert.Equal("Contoso Package Source", packageSources[1].Name);
            }
        }
Example #8
0
        public NuGetViewModel()
        {
            try
            {
                _settings = Settings.LoadDefaultSettings(
                    root: null,
                    configFileName: null,
                    machineWideSettings: new CommandLineMachineWideSettings());

                _sourceProvider = new PackageSourceProvider(_settings);

                GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(_settings);

                _packageSources = GetPackageSources();

                _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(_sourceProvider);
            }
            catch (Exception e)
            {
                _initializationException = ExceptionDispatchInfo.Capture(e);
            }
        }
Example #9
0
#pragma warning disable CS8618 // Non-nullable field is uninitialized.
        public NuGetViewModel()
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
        {
            try {
                var settings = Settings.LoadDefaultSettings(
                    root: null,
                    configFileName: null,
                    machineWideSettings: new XPlatMachineWideSetting());

                GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);
                _configFilePaths    = settings.GetConfigFilePaths();
                _packageSources     = SettingsUtility.GetEnabledSources(settings);

                DefaultCredentialServiceUtility.SetupDefaultCredentialService(NullLogger.Instance, nonInteractive: false);

                var sourceProvider = new PackageSourceProvider(settings);
                _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(sourceProvider);
            }
            catch (Exception e) {
                _initializationException = ExceptionDispatchInfo.Capture(e);
            }
        }
Example #10
0
        public NuGetViewModel(ITelemetryProvider telemetryProvider)
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
        {
            try
            {
                ISettings settings;

                try
                {
                    settings = Settings.LoadDefaultSettings(
                        root: null,
                        configFileName: null,
                        machineWideSettings: new XPlatMachineWideSetting());
                }
                catch (NuGetConfigurationException ex)
                {
                    telemetryProvider.ReportError(ex);

                    // create default settings using a non-existent config file
                    settings = new Settings(nameof(RoslynPad));
                }

                GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);
                _configFilePaths    = SettingsUtility.GetConfigFilePaths(settings);
                _packageSources     = SettingsUtility.GetEnabledSources(settings);

                DefaultCredentialServiceUtility.SetupDefaultCredentialService(NullLogger.Instance, nonInteractive: false);

                var sourceProvider = new PackageSourceProvider(settings);
                _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(sourceProvider);
            }
            catch (Exception e)
            {
                _initializationException = ExceptionDispatchInfo.Capture(e);
            }
        }
Example #11
0
 private static ProxyCache FromDefaultSettings()
 {
     return(new ProxyCache(
                Settings.LoadDefaultSettings(root: null, configFileName: null, machineWideSettings: null),
                new EnvironmentVariableWrapper()));
 }