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); }
protected override void ExecuteTask() { if (ProjectFile == null && ProjectDir == null) throw new ValidationException("Either project or project-dir must be set on <nuget-get-dependencies />."); string dir = SolutionDir.FullName; _fileSystem = new PhysicalFileSystem(dir); string projectDir = ProjectFile == null ? ProjectDir.FullName : ProjectFile.Directory.FullName; RepositoryFactory = new PackageRepositoryFactory(); SourceProvider = new PackageSourceProvider(new Settings(_fileSystem)); var packagesConfigFiles = Directory.GetFiles(projectDir, Constants.PackageReferenceFile, SearchOption.AllDirectories); var project = packagesConfigFiles.Select(GetProject) .Where(p => p.Project != null) .SingleOrDefault(); if (project == null) { throw new BuildException("No project found", Location); } string repositoryPath = GetRepositoryPathFromSolution(dir); IPackageRepository sourceRepository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source); var references = GetReferences(project.PackagesConfigPath, project.Project, repositoryPath, sourceRepository); var deps = new NuGetDependencies { Dependencies = references.Select(GetDependency).ToArray() }; Project.DataTypeReferences.Add(ReferenceId, deps); Log(Level.Info, "Found {0} dependencies", deps.Dependencies.Length); }
static void InitializeCredentialProvider() { ISettings settings = Settings.LoadDefaultSettings(null, null, null); var packageSourceProvider = new PackageSourceProvider(settings); var credentialProvider = new SettingsCredentialProvider(new SharpDevelopCredentialProvider(), packageSourceProvider); HttpClient.DefaultCredentialProvider = credentialProvider; }
public NugetStore(string rootDirectory, string configFile = DefaultConfig, string overrideFile = OverrideConfig) { if (rootDirectory == null) throw new ArgumentNullException(nameof(rootDirectory)); if (configFile == null) throw new ArgumentNullException(nameof(configFile)); if (overrideFile == null) throw new ArgumentNullException(nameof(overrideFile)); // First try the override file with custom settings var configFileName = overrideFile; var configFilePath = Path.Combine(rootDirectory, configFileName); if (!File.Exists(configFilePath)) { // Override file does not exist, fallback to default config file configFileName = configFile; configFilePath = Path.Combine(rootDirectory, configFileName); if (!File.Exists(configFilePath)) { throw new ArgumentException($"Invalid installation. Configuration file [{configFile}] not found", nameof(configFile)); } } rootFileSystem = new PhysicalFileSystem(rootDirectory); Settings = NuGet.Settings.LoadDefaultSettings(rootFileSystem, configFileName, null); string installPath = Settings.GetRepositoryPath(); packagesFileSystem = new PhysicalFileSystem(installPath); packageSourceProvider = new PackageSourceProvider(Settings); repositoryFactory = new PackageRepositoryFactory(); SourceRepository = packageSourceProvider.CreateAggregateRepository(repositoryFactory, true); pathResolver = new DefaultPackagePathResolver(packagesFileSystem); Manager = new PackageManager(SourceRepository, pathResolver, packagesFileSystem); var mainPackageList = Settings.GetConfigValue(MainPackagesKey); if (string.IsNullOrWhiteSpace(mainPackageList)) { throw new InvalidOperationException($"Invalid configuration. Expecting [{MainPackagesKey}] in config"); } MainPackageIds = mainPackageList.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); VSIXPluginId = Settings.GetConfigValue(VsixPluginKey); if (string.IsNullOrWhiteSpace(VSIXPluginId)) { throw new InvalidOperationException($"Invalid configuration. Expecting [{VsixPluginKey}] in config"); } RepositoryPath = Settings.GetConfigValue(RepositoryPathKey); if (string.IsNullOrWhiteSpace(RepositoryPath)) { RepositoryPath = DefaultGamePackagesDirectory; } // Setup NugetCachePath in the cache folder Environment.SetEnvironmentVariable("NuGetCachePath", Path.Combine(rootDirectory, "Cache", RepositoryPath)); }
public NuGetFeedSourceStore(IPreferences preferences) : base(preferences) { _packageSourceProvider = new PackageSourceProvider( // Do not load user settings or machine wide settings for WebMatrix 'nuget.org' feed // In other words, pass all null to LoadDefaultSettings Settings.LoadDefaultSettings(null, null, null), defaultSources: new[] { new PackageSource("https://www.nuget.org/api/v2", Resources.NuGet_PackageSourceName) }); }
protected override void ExecuteTask() { string dir = SolutionDir.FullName; _fileSystem = new PhysicalFileSystem(dir); RepositoryFactory = new PackageRepositoryFactory(); SourceProvider = new PackageSourceProvider(new Settings(_fileSystem)); UpdateAllPackages(dir); }
public async Task<Package> LoadAsync(string id, string version) { var logger = _loggerFactory.CreateLogger<NuGetPackageLoader>(); var sourceProvider = new PackageSourceProvider( NullSettings.Instance, new[] { new PackageSource(NuGetConstants.DefaultFeedUrl), new PackageSource("https://www.myget.org/F/aspnetvnext/api/v2"), }); var feeds = sourceProvider .LoadPackageSources() .Select(source => PackageSourceUtils.CreatePackageFeed( source, noCache: false, ignoreFailedSources: false, reports: logger.CreateReports())) .Where(f => f != null); logger.LogInformation($"Looking up {id} v{version} from nuget"); var packages = (await Task.WhenAll(feeds.Select(feed => feed.FindPackagesByIdAsync(id)))) .SelectMany(_ => _) .OrderByDescending(p => p.Version); var package = version == null ? packages.FirstOrDefault() : packages.FirstOrDefault(p => p.Version == new SemanticVersion(version)); if (package == null) { logger.LogError($"Unable to locate {id} v{version}"); return null; } logger.LogInformation($"Found version {package.Version} of {package.Id}"); var pkgStreams = await Task.WhenAll(feeds.Select(feed => { try { return feed.OpenNupkgStreamAsync(package); } catch { return null; } })); var pkgStream = pkgStreams.FirstOrDefault(s => s != null); var zipPackage = new ZipPackage(pkgStream); if (zipPackage == null) { logger.LogError($"Unable to open package stream for {id} v{version}"); return null; } return zipPackage.ToPackage(packages.Select(p => p.Version.ToString()).ToList(), logger); }
internal static PackageSourceProvider CreateSourceProvider(ISettings settings) { var defaultPackageSource = new PackageSource(DefaultFeedUrl); var packageSourceProvider = new PackageSourceProvider( settings, new[] { defaultPackageSource }, new Dictionary <PackageSource, PackageSource> { }); packageSourceProvider.LoadPackageSources().ToList(); return(packageSourceProvider); }
internal static PackageSourceProvider CreateSourceProvider(ISettings settings) { var defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl); var officialPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl, NuGetResources.OfficialPackageSourceName); var v1PackageSource = new PackageSource(NuGetConstants.V1FeedUrl, NuGetResources.OfficialPackageSourceName); var legacyV2PackageSource = new PackageSource(NuGetConstants.V2LegacyFeedUrl, NuGetResources.OfficialPackageSourceName); var packageSourceProvider = new PackageSourceProvider( settings, new[] { defaultPackageSource }, new Dictionary<PackageSource, PackageSource> { { v1PackageSource, officialPackageSource }, { legacyV2PackageSource, officialPackageSource } } ); return packageSourceProvider; }
internal static PackageSourceProvider CreateSourceProvider(ISettings settings) { var defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl); var officialPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl, NuGetResources.OfficialPackageSourceName); var v1PackageSource = new PackageSource(NuGetConstants.V1FeedUrl, NuGetResources.OfficialPackageSourceName); var legacyV2PackageSource = new PackageSource(NuGetConstants.V2LegacyFeedUrl, NuGetResources.OfficialPackageSourceName); var packageSourceProvider = new PackageSourceProvider( settings, new[] { defaultPackageSource }, new Dictionary <PackageSource, PackageSource> { { v1PackageSource, officialPackageSource }, { legacyV2PackageSource, officialPackageSource } } ); return(packageSourceProvider); }
private void Initialize(IFileSystem fileSystem, IConsole console) { using (var catalog = new AggregateCatalog(new AssemblyCatalog(GetType().Assembly))) { if (!IgnoreExtensions) { AddExtensionsToCatalog(catalog, console); } using (var container = new CompositionContainer(catalog)) { var settings = Settings.LoadDefaultSettings(fileSystem); var defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl); var officialPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl, NuGetResources.OfficialPackageSourceName); var v1PackageSource = new PackageSource(NuGetConstants.V1FeedUrl, NuGetResources.OfficialPackageSourceName); var legacyV2PackageSource = new PackageSource(NuGetConstants.V2LegacyFeedUrl, NuGetResources.OfficialPackageSourceName); var packageSourceProvider = new PackageSourceProvider( settings, new[] { defaultPackageSource }, new Dictionary <PackageSource, PackageSource> { { v1PackageSource, officialPackageSource }, { legacyV2PackageSource, officialPackageSource } } ); // Register an additional provider for the console specific application so that the user // will be prompted if a proxy is set and credentials are required var credentialProvider = new SettingsCredentialProvider(new ConsoleCredentialProvider(console), packageSourceProvider, console); HttpClient.DefaultCredentialProvider = credentialProvider; container.ComposeExportedValue <IConsole>(console); container.ComposeExportedValue <ISettings>(settings); container.ComposeExportedValue <IPackageRepositoryFactory>(new NuGet.Common.CommandLineRepositoryFactory()); container.ComposeExportedValue <IPackageSourceProvider>(packageSourceProvider); container.ComposeExportedValue <ICredentialProvider>(credentialProvider); container.ComposeExportedValue <IFileSystem>(fileSystem); container.ComposeParts(this); } } }
public AddInRepository(params AddInSource[] sources) { List<PackageSource> packageSources = new List<PackageSource>(); foreach (AddInSource source in sources) { PackageSource packageSource = new PackageSource(source.Source, source.Name, isEnabled: true, isOfficial: source.IsOfficial); packageSources.Add(packageSource); } PackageSourceProvider packageSourceProvider = new PackageSourceProvider(new NullSettings(), packageSources); IPackageRepositoryFactory packageRepositoryFactory = new PackageRepositoryFactory(); // TODO probably turn this off and report proper errors this._repository = packageSourceProvider.GetAggregate(packageRepositoryFactory, ignoreFailingRepositories: true); }
/// <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("settings"); } if (logger == null) { throw new ArgumentNullException("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; }
/// <summary> /// Initialize NugetStore using <paramref name="rootDirectory"/> as location of the local copies, /// and a configuration file <paramref name="configFile"/> as well as an override configuration /// file <paramref name="overrideFile"/> where all settings of <paramref name="overrideFile"/> also /// presents in <paramref name="configFile"/> take precedence. /// </summary> /// <param name="rootDirectory">The location of the Nuget store.</param> /// <param name="configFile">The configuration file name for the Nuget store, or <see cref="DefaultConfig"/> if not specified.</param> /// <param name="overrideFile">The override configuration file name for the Nuget store, or <see cref="OverrideConfig"/> if not specified.</param> public NugetStore(string rootDirectory, string configFile = DefaultConfig, string overrideFile = OverrideConfig) { if (rootDirectory == null) { throw new ArgumentNullException(nameof(rootDirectory)); } if (configFile == null) { throw new ArgumentNullException(nameof(configFile)); } if (overrideFile == null) { throw new ArgumentNullException(nameof(overrideFile)); } // First try the override file with custom settings var configFileName = overrideFile; var configFilePath = Path.Combine(rootDirectory, configFileName); if (!File.Exists(configFilePath)) { // Override file does not exist, fallback to default config file configFileName = configFile; configFilePath = Path.Combine(rootDirectory, configFileName); if (!File.Exists(configFilePath)) { throw new ArgumentException($"Invalid installation. Configuration file [{configFile}] not found", nameof(configFile)); } } var rootFileSystem = new PhysicalFileSystem(rootDirectory); RootDirectory = rootFileSystem.Root; settings = new Settings(rootFileSystem, configFileName, false); InstallPath = settings.GetValue(ConfigurationConstants.Config, RepositoryPathKey, true); if (!string.IsNullOrEmpty(InstallPath)) { InstallPath = InstallPath.Replace('/', Path.DirectorySeparatorChar); } var mainPackageList = settings.GetValue(ConfigurationConstants.Config, MainPackagesKey, false); if (string.IsNullOrWhiteSpace(mainPackageList)) { throw new InvalidOperationException($"Invalid configuration. Expecting [{MainPackagesKey}] in config"); } MainPackageIds = mainPackageList.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); VsixPluginId = settings.GetValue(ConfigurationConstants.Config, VsixPluginKey, false); if (string.IsNullOrWhiteSpace(VsixPluginId)) { throw new InvalidOperationException($"Invalid configuration. Expecting [{VsixPluginKey}] in config"); } RepositoryPath = settings.GetValue(ConfigurationConstants.Config, RepositoryPathKey, false); if (string.IsNullOrWhiteSpace(RepositoryPath)) { RepositoryPath = DefaultGamePackagesDirectory; } // Setup NugetCachePath in the cache folder CacheDirectory = Path.Combine(rootDirectory, "Cache"); Environment.SetEnvironmentVariable("NuGetCachePath", CacheDirectory); var packagesFileSystem = new PhysicalFileSystem(InstallPath); PathResolver = new PackagePathResolver(packagesFileSystem); var packageSourceProvider = new PackageSourceProvider(settings); SourceRepository = packageSourceProvider.CreateAggregateRepository(new PackageRepositoryFactory(), true); var localRepo = new SharedPackageRepository(PathResolver, packagesFileSystem, rootFileSystem); manager = new NuGet.PackageManager(SourceRepository, PathResolver, packagesFileSystem, localRepo); manager.PackageInstalling += OnPackageInstalling; manager.PackageInstalled += OnPackageInstalled; manager.PackageUninstalling += OnPackageUninstalling; manager.PackageUninstalled += OnPackageUninstalled; }
protected override void ExecuteTask() { string dir = SolutionDir.FullName; string repositoryPath = GetRepositoryPathFromSolution(dir); _fileSystem = new PhysicalFileSystem(dir); RepositoryFactory = new PackageRepositoryFactory(); SourceProvider = new PackageSourceProvider(new Settings(_fileSystem)); var repo = RepositoryFactory.CreateRepository(repositoryPath); Log(Level.Debug, "Repo: {0}, Count: {1}", repo.Source, repo.GetPackages().Count()); var fw = VersionUtility.ParseFrameworkName(Framework); List<string> files = new List<string>(), references = new List<string>(); foreach (var deps in Dependencies) { foreach (var dep in deps.Dependencies) { var package = repo.FindPackage(dep.Id, dep.VersionSpec, !String.IsNullOrWhiteSpace(dep.VersionSpec.MinVersion.SpecialVersion), false); if (package == null) package = repo.FindPackage(dep.Id, dep.VersionSpec, true, false); if (package == null) package = repo.FindPackage(dep.Id, dep.VersionSpec, true, true); if (package == null) throw new BuildException(String.Format("Can't find package {0} with min version {1}", dep.Id, dep.MinVersion), Location); string pkgPath = Path.Combine(repositoryPath, package.Id + "." + package.Version); var package_files = package.GetLibFiles().ToList(); IEnumerable<IPackageFile> compatible_files; Log(Level.Debug, "Found package {0} with {1} file(s) - {2}", package.Id, package_files.Count, package.GetType()); if (!VersionUtility.TryGetCompatibleItems(fw, package_files, out compatible_files)) throw new BuildException("Couldn't get compatible files."); foreach (var f in compatible_files) { var extension = Path.GetExtension(f.Path); var path = Path.Combine(pkgPath, f.Path); Log(Level.Debug, " - Found compatible file {1} ({0}) - {2}", f.Path, f.EffectivePath, path); if (extension == ".dll" || extension == ".exe") references.Add(path); files.Add(path); } } } if (FilesId != null) { PatternSet ps = new PatternSet(); ps.Include.AddRange(files.Select(MakePattern).ToArray()); Project.DataTypeReferences.Add(FilesId, ps); } if (ReferencesId != null) { PatternSet ps = new PatternSet(); ps.Include.AddRange(references.Select(MakePattern).ToArray()); Project.DataTypeReferences.Add(ReferencesId, ps); } Log(Level.Info, "Found {0} file(s) and {1} reference(s)", files.Count, references.Count); }
public NuGetConfig(ISettings settings, PackageSourceProvider sources) { Settings = settings; Sources = sources; }
private void Initialize(IFileSystem fileSystem) { using (var catalog = new AggregateCatalog(new AssemblyCatalog(GetType().Assembly))) { if (!IgnoreExtensions) { AddExtensionsToCatalog(catalog); } using (var container = new CompositionContainer(catalog)) { var settings = GetCommandLineSettings(fileSystem); var defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl); var officialPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl, NuGetResources.OfficialPackageSourceName); var v1PackageSource = new PackageSource(NuGetConstants.V1FeedUrl, NuGetResources.OfficialPackageSourceName); var packageSourceProvider = new PackageSourceProvider( settings, new[] { defaultPackageSource }, new Dictionary<PackageSource, PackageSource> { { v1PackageSource, officialPackageSource } } ); container.ComposeExportedValue<ISettings>(settings); container.ComposeExportedValue<IPackageRepositoryFactory>(new NuGet.Common.CommandLineRepositoryFactory()); container.ComposeExportedValue<IPackageSourceProvider>(packageSourceProvider); container.ComposeParts(this); } } }
private void Initialize(IFileSystem fileSystem, IConsole console) { using (var catalog = new AggregateCatalog(new AssemblyCatalog(GetType().Assembly))) { if (!IgnoreExtensions) { AddExtensionsToCatalog(catalog); } using (var container = new CompositionContainer(catalog)) { var settings = GetCommandLineSettings(fileSystem); var defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl); var officialPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl, NuGetResources.OfficialPackageSourceName); var v1PackageSource = new PackageSource(NuGetConstants.V1FeedUrl, NuGetResources.OfficialPackageSourceName); var legacyV2PackageSource = new PackageSource(NuGetConstants.V2LegacyFeedUrl, NuGetResources.OfficialPackageSourceName); var packageSourceProvider = new PackageSourceProvider( settings, new[] { defaultPackageSource }, new Dictionary<PackageSource, PackageSource> { { v1PackageSource, officialPackageSource }, { legacyV2PackageSource, officialPackageSource } } ); // Register an additional provider for the console specific application so that the user // will be prompted if a proxy is set and credentials are required var credentialProvider = new SettingsCredentialProvider(new ConsoleCredentialProvider(), packageSourceProvider, console); HttpClient.DefaultCredentialProvider = credentialProvider; container.ComposeExportedValue<IConsole>(console); container.ComposeExportedValue<ISettings>(settings); container.ComposeExportedValue<IPackageRepositoryFactory>(new NuGet.Common.CommandLineRepositoryFactory()); container.ComposeExportedValue<IPackageSourceProvider>(packageSourceProvider); container.ComposeExportedValue<ICredentialProvider>(credentialProvider); container.ComposeParts(this); } } }
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(); }
static SettingsCredentialProvider CreateSettingsCredentialProvider (ICredentialProvider credentialProvider) { ISettings settings = Settings.LoadDefaultSettings (null, null, null); var packageSourceProvider = new PackageSourceProvider (settings); return new SettingsCredentialProvider(credentialProvider, packageSourceProvider); }
static SettingsCredentialProvider CreateSettingsCredentialProvider (ICredentialProvider credentialProvider) { ISettings settings = LoadSettings (); var packageSourceProvider = new PackageSourceProvider (settings); return new SettingsCredentialProvider(credentialProvider, packageSourceProvider); }